B God Create Math 思维问题


B.God Create Math

 

There is a saying: computer was the crystallizationof men' intelligence, but math is  fromgod. Today, god also sends us a problem.

                sin (n! * [ln(n)] * fib(n) %2012)

Some explanations:

In sin(x), x is a radian.

0! = 1, n! = (n-1)! * n (n >= 1).

[x] is the integer part of a floatingnumber.

fib(0) = fib(1) = 1, and fib(n) = fib(n-1)+ fib(n-2) (n >= 2).

Your task is calculating the value with agiven N.

 

Input

 

The first line contains a single integer T,indicating the number of test cases.

Each test case contains one integer N (1<= N <= 1000 000 000).

 

Output

 

For each test case, output the resultrounded to three fractional digits.

 

Sample Input

 

3

1

4

10

 

Sample Output

 

0.000

0.581

0.978

队内赛出了这道题,就是木有注意到n!到了2012就mod2012余0了这样对于  sin (n! * [ln(n)] * fib(n) %2012)  这个式子来讲,当n超过了2012就mod2012余0了,这样要注意 就是sin(0)为0.000 这里要注意 然后就是计算2012以内的阶乘和fibnaci的值即可 求ln 用log函数。  我直接把fibnaci看成矩阵乘法求大的fabonaci了~~就悲剧了。


#include<stdio.h>
#include<math.h>
#include<string.h>
int a[2100],fib[2100];
void facotoria()    //求阶乘
{
   int i;
   a[0]=1;
   a[1]=1;
   for(i=2;i<=2011;i++)     
     a[i]=(a[i-1]*i)%2012;
}

void f()   //求fibnaci
{
   int i;
   fib[0]=1;
   fib[1]=1;     
   for(i=2;i<=2011;i++)     
      fib[i]=(fib[i-1]%2012+fib[i-2]%2012)%2012;   
}


int main()
{ 
     facotoria();
     f();
     double ans;
     int n,num;
     scanf("%d",&n);
     while(n--)
     {
         scanf("%d",&num);
         if(num>=2012){printf("0.000\n");continue;}  //当大于2011 的时候值为0.000  注意要输出0.000     
         else printf("%.3lf\n", sin (   (double) ( (a[num]*fib[num])%2012*(int)log(num) %2012 ) )  );      
               
     }
    
    


你可能感兴趣的:(Math,Integer,input,each,output)