| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
总是TLE,郁闷!!!#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
int prime[500000];
int pn;
void init(){
pn=1;
prime[0]=2;
int i=3,j=0;
for(i=3;i<=100000;i++){
bool find=false;
for(j=0;prime[j]<=sqrt(i)&&j<pn;j++){
if(i%prime[j]==0){
find=true;
break;
}
}
if(!find){
prime[pn++]=i;
}
}
}
bool binarysearch(int p){
int i=0,j=pn-1;
while(i<=j){
int mid=(i+j)/2;
if(prime[mid]==p)return true;
else if(prime[mid]<p){
i=mid+1;
}else{
j=mid-1;
}
}
return false;
}
void main(){
// ifstream cin("data.txt");
init();
while(1){
int a,d,n,i,j,k;
cin>>a>>d>>n;
if(a==0&&d==0)break;
k=a;
int count=0;
// if(binarysearch(a))n++;
for(i=0;;i++){
int cur=a+d*i;
if(binarysearch(cur))count++;
if(count==n)break;
}
cout<<a+d*i<<endl;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator