数学专项number_theory:UVa 10236
来源:互联网 发布:淘宝好的军品店 编辑:程序博客网 时间:2024/06/05 02:33
需要推之一个结论,即gcd(f[n],f[m])=f[gcd(n,m)],有了这个结论就可以做这题了。在递推fibonacci数列的时候需要一些小技巧。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <iomanip>using namespace std;const int maxn=22010;const long double inf=1e9;int prime[100000],p;int vis[1000010];long double f[1000010];void init(){ memset(vis,0,sizeof(vis)); for(int i=2;i<=1000;i++) { for(int j=i*i;j<=1000000;j+=i) if(!vis[j]) vis[j]=1; } p=0; for(int i=2;i<=1000000;i++) if(!vis[i]) prime[p++]=i; prime[0]=3;prime[1]=4;}int main(){ init(); int n; f[1]=f[2]=1; int flag=0; for(int i=3;i<=1000000;i++) { if(flag) f[i]=f[i-1]+f[i-2]/10; else f[i]=f[i-1]+f[i-2]; flag=0; if(f[i]>=inf) { flag=1; f[i]/=10; } } while(~scanf("%d",&n)) { printf("%d\n",(int)f[prime[n-1]]); } return 0;}
- 数学专项number_theory:UVa 10236
- 数学专项number_theory:UVa 10515
- 数学专项number_theory:UVa 10622
- 数学专项number_theory:UVa 10127
- 数学专项number_theory:UVa 10090
- 数学专项number_theory:UVa 10539
- 数学专项number_theory:UVa 11105
- 数学专项number_theory:UVa 11490
- 数学专项number_theory:UVa 11728
- 数学专项number_theory:UVa 10692
- 数学专项number_theory:UVa 10951
- 数学专项number_theory:UVa 756
- 数学专项number_theory:UVa 718
- 数学专项number_theory:UVa 294
- 数学专项number_theory:UVa 10368
- 数学专项number_theory:UVa 10162
- 数学专项number_theory:UVa 11768
- 数学专项number_theory:LA 4079
- Cocos2d中使用颜色混合:加算,减算
- <Leetcode>Trapping Rain Water
- 11月18,时隔3个多月,又开始了acm
- 接上一篇改篇:Java EE7,Tomcat8,HTML5,WebSocket1编码器与解码器的例子
- UVA 10245 (13.11.08)
- 数学专项number_theory:UVa 10236
- 阿里云主机中apache的主页
- xapian 1.2.x在VC下编译问题的浅析(可能是一)
- 查看数据库连接数
- 不只是技术!成为IT经理必备的十大软技能
- ruby中的一个问题
- StoryBoard可能出现错误解决
- [数据结构学习]单链表常用操作
- 1108