hdu5407数学

hdu5407数学_第1张图片
神马鬼?

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeSet;

import org.omg.CORBA.Object;




public class Main {


    public static void main(String[] args) throws IOException{

           StreamTokenizer cin = new StreamTokenizer(new BufferedInputStream(System.in)); 
           InputReader in = new InputReader(System.in)  ;
           PrintWriter out = new PrintWriter(System.out) ;

           int t = in.nextInt() ;
           while(t-- > 0){

                new Task().solve(in, out)  ;   //out.flush() ;
           }

           out.flush() ; 


    }


}

class   Task{
        static final int N = 1000001 ;
        static final long mod = 1000000007L ;

        static long[] f = new long[N+1] ;

        static boolean[] vis = new boolean[1003] ;
        static int[] prime = new int[1003] ;
        static int  pid ;

        static{
             pid = 0 ;
             Arrays.fill(vis, false) ;
             for(int i = 2 ; i <= 1000 ; i++){
                 if(! vis[i])
                       prime[pid++] = i ;
                 for(int j = 0 ; j < pid && prime[j] * i <= 1000 ; j++){
                            vis[prime[j]*i] = true ;
                            if(i % prime[j] == 0) break ;
                 }
             }

             f[1] = 1 ;
             for(int i = 2 ; i <= N ; i++){
                 int n = i ;
                 int p = -1 ;
                 int d = 0 ;
                 for(int k = 0 ; k < pid && prime[k] <= n ; k++){
                     if(n % prime[k] == 0){
                          d = 1 ;
                          while(n % prime[k] == 0){
                              n /= prime[k] ;
                          }
                          if(n == 1) p = prime[k] ;
                          break ;
                     }
                 }
                 if(d == 0 && n != 1) p = n ;

                 if(p == -1) f[i] = f[i-1] ;
                 else f[i] = f[i-1] * p % mod ;
             }
        }

        long  Pow(int x , long y){
            long s = 1 , r = (long)x ;
            for(; y > 0; y >>= 1){
                 if((y & 1) > 0){
                     s = (s * r) % mod ;
                 }
                 r = (r * r) % mod ;
            }
            return s ;
        }

        public void solve(InputReader in , PrintWriter out) throws IOException{
               int n = in.nextInt() ;
               long ans = f[n+1] * Pow(n+1 , mod-2) % mod ;
               out.println(ans);
        }

}


class InputReader{
        public BufferedReader  reader;
        public StringTokenizer  tokenizer;

        public InputReader(InputStream stream){
                    reader = new BufferedReader(new InputStreamReader(stream), 32768) ;
                    tokenizer = null ;
        }

        public String next(){
                    while(tokenizer == null || ! tokenizer.hasMoreTokens()){
                        try{
                                tokenizer = new StringTokenizer(reader.readLine());
                        }catch (IOException e) {
                                throw new RuntimeException(e);
                        }
                    }
                    return tokenizer.nextToken();  
        }

        public int  nextInt() {
                    return Integer.parseInt(next());
        }

        public long nextLong() {
                    return Long.parseLong(next());
        }

}

你可能感兴趣的:(hdu5407数学)