poj3006
来源:互联网 发布:单片机交通灯设计方案 编辑:程序博客网 时间:2024/06/05 21:54
摘要:这题本身简单,但是暴力破解很可能超过时间界.最好的选择是采取素数筛法,以空间换时间,这样所有的素数都可以用O(1)的时间测出来.
#include "stdafx.h"#include "iostream"using namespace std;bool Isprime[1000005];void Find(int a,int d,int n){ int x = a - d,count = 0; while(count<=n-1) { x += d; if(Isprime[x] == true) { count++; } } cout<<x<<endl;}int main(){ int a,d,n,k=0; int Prime[100000]; memset(Isprime,true,sizeof(Isprime)); Isprime[1] =false; Prime[k++] = 2; for(int i = 1;i<=1000000;i ++ ) { while(Isprime[i] == false)//找到第一个未删除的素数 { i++; } Prime[k++] = i; for(int j = i*2;j<=1000000;j += i ) Isprime[j] = false; } while(1) { int t =0,count = 0; cin>>a; cin>>d; cin>>n; if((a||d||n) ==0) break; Find(a,d,n); } return 0;}
0 0
- poj3006
- poj3006
- poj3006
- poj3006
- poj3006
- POJ3006
- poj3006
- poj3006
- POJ3006
- POJ3006
- poj3006
- poj3006
- POJ3006
- poj3006
- poj3006
- poj3006 素数
- POJ3006 解题报告
- poj3006(素数筛法)
- Info.plist Utility Error: “Info.plist couldn't be opened because there is no such file”
- unity5在mx4下crash
- MFC 多线程的使用
- 服务器设计框架简介
- 从零开始自学Swift(四)
- poj3006
- K-近邻算法(KNN)
- 罗爷:创新法律服务交易模式 找到你的专属lawyer
- hive UDF使用本地文件资源
- iOS objective-c NSDictionary有序排列
- 怎么在Android中设置一个color.xml快速获取颜色
- linux 部署多个tomcat
- php 环境配置(windows环境)
- android 访问c# webservice 实现登陆注册功能(android 上传json到服务器)