数学专项number_theory:LA 4382
来源:互联网 发布:网络6524是什么意思啊 编辑:程序博客网 时间:2024/05/24 08:33
利用wilson’s theorem可知所求的就是sum{[3*k+7为素数]|1<=k<=n},只要预处理出3000007内的素数表就可以预处理出解,然后就可以直接输出了。
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn=5000010;int vis[maxn];int cnt[maxn];void init(){ memset(vis,0,sizeof(vis)); memset(cnt,0,sizeof(cnt)); for(int i=2;i<=2000;i++) if(!vis[i]) { for(int j=i*i;j<=4000000;j+=i) vis[j]=1; } for(int i=8;i<=4000000;i++) if((!vis[i]) && (i-7)%3==0) cnt[(i-7)/3]=1; for(int i=1;i<=1000000;i++) cnt[i]+=cnt[i-1];}int main(){ // freopen("in.txt","r",stdin); init(); int q,n; scanf("%d",&q); while(q--) { scanf("%d",&n); printf("%d\n",cnt[n]); } return 0;}
- 数学专项number_theory:LA 4382
- 数学专项number_theory:LA 4079
- 数学专项number_theory:LA 2955
- 数学专项number_theory:LA 3262
- 数学专项number_theory:LA 3521
- 数学专项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
- new和malloc的区别
- java下载网络文件, ppt,pdf,图片
- android学习 wifi连接的注意的问题
- 结构体定义寄存器方法(很流行哦)
- ABAP取字符串中的连续数字
- 数学专项number_theory:LA 4382
- 将网页添加至收藏夹代码
- 2013-10-28
- 数据结构上机题目--dijkstra
- C语言学生信息管理系统 (单链表版)【无图,未调试】
- sqlite数据库执行监控
- 【C语言知识点】菜鸟程序媛的杂记总结1~10
- Automatic SQL Tuning in Oracle Database
- matlab sort矩阵排序