正文

happy 20042007-02-22 10:30:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/xiaoxiaofeng/23429.html

分享到:

#include<iostream>using namespace std; int left2[29],left3[29],left167[29]; int left(int i,double x){ if(x>28)  x=x-(int)(x/28)*28; switch (i) { case 2: return left2[(int)x-1]; case 3: return left3[(int)x-1]; case 167:return left167[(int)x-1]; } return 0;}   int happy2004(double x){ if(x>28)  x=x-(int)(x/28)*28; if(x==1)  return 6; else {   int n1=0,n2=0,n3=0,n4=0,n5=0,cash1=0,cash2=0;  cash1=(29-((left(3,x+1)-1)*14)%29)%29;  cash2=(29-(left(167,x)-1)*11%29)%29;  n1=((left(2,2*x+1)-1)*cash1*left(167,x))%29;  n2=(left(2,2*x-1)*cash1*cash2)%29;  n3=(2*n2)%29;  n4=(left(3,x)*(left(2,2*x-1)-1)*cash2)%29;  n5=happy2004(x-1);  return (n1+n2+n3+n4+n5)%29; }} int main(int argc, char* argv[]){ int i2=2,i3=3,i167=22;       double n;       while(cin>>n)   {    i2=2,i3=3,i167=22;    for(int j=0;j<29;j++)    {     left2[j]=i2;     i2=(i2*2)%29;       left3[j]=i3;     i3=(i3*3)%29;       left167[j]=i167;     i167=(i167*167)%29;    }    n=(double)happy2004(n);    cout<<n<<endl;   }    return 0;} //n可以取到10000000.

阅读(132) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册