暑期9_15队内练习赛 B题 大数取模+矩阵快速幂

题目大意:求sin(n!*ln(n)*f[n]%2012)的结果,n<=10^9,f[n]是斐波那契数列的第n项

思路:哎~~菜菜菜啊~~却不是我的菜~~n!至少到2012都不用求后面的啦~~因为取余都为0了~~我还在傻乎乎的用矩阵求快速幂·~呜呜~~菜菜菜啊~~

AC program:(暴力无优化代码:没有优化2012后都为0的情况)

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
int aa[2015];
int f[1000005];
int sum;
struct node
{
  int a,b,c,d;       
}fsum,gg;

node ju(node aaa, node bbb)
{
  node ccc;
  ccc.a=(aaa.a*bbb.a)%2012+(aaa.b*bbb.c)%2012;
  ccc.b=(aaa.a*bbb.b)%2012+(aaa.b*bbb.d)%2012;
  ccc.c=(aaa.c*bbb.a)%2012+(aaa.d*bbb.c)%2012;
  ccc.d=(aaa.c*bbb.b)%2012+(aaa.d*bbb.d)%2012;
  //cout<<"ab cd "<<ccc.a<<' '<<ccc.b<<' '<<ccc.c<<' '<<ccc.d<<endl;
  //return ccc;
  return ccc;     //少了个返回让我的数据情何以堪
}
node fn(int n)
{
   if(n==1)return gg;
   //fn(n/2);              //做这个矩阵乘法也让我收获颇丰啊~~也是菜的证明·~~

                          //我在这多写了个f(n/2)不知道把电脑搞死到什么程度~~囧。。
   node tmp=fn(n/2); 
   node tmppp=ju( tmp,tmp); 
   if(n%2==0) return tmppp;
   return ju( tmppp,gg );    
        
}
int main()
{
gg.a=1;
gg.b=1;
gg.c=1;
gg.d=0;
memset(aa,0,sizeof(aa));
aa[1]=1;
for(int i=2;i<=2012;i++)
   {
      aa[i]=(aa[i-1]*i)%2012;        
   }     
int test,n;
scanf("%d",&test);
while(test--)
{
   scanf("%d",&n);
   fsum= fn(n);
   //cout<<fsum.b<<endl;
   //cout<<"fsum "<<fsum.a<<' '<<fsum.b<<' '<<fsum.c<<' '<<fsum.d<<endl;
   sum=1;
   int tmp=n/2012;
   if(tmp>=1)
        {
          for(int i=1;i<=2012;i++)
          {
                   
                 sum=  (aa[2012]* (tmp%2012))%2012;    
          }     
        }
   int kg=n%2012;
    if(kg!=0)
    {
      
        sum=sum*aa[kg];       
             
    }

           int ttt=(int)log((double)n);
                                         //cout<<"ttt "<<ttt<<endl;
                                         //cout<<"sum "<<sum<<endl;
           int ppp=(  sum* ( ttt%2012) *fsum.a)%2012;
                                          //cout<<"ppp "<<ppp<<endl;
           double win=sin( (double)ppp); 
           printf("%.3lf\n",win);
   
                
               
}
//system("pause");
return 0;}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值