Dirichlet's Theorem on Arithmetic Progressions POJ - 3006 线性欧拉筛

 

  题意 给出a d n    给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出

  直接线性筛模拟即可

 

 

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4 bool Is_Primes[1000005];
 5 int Primes[1000005];
 6 int A[1000005];
 7 int cnt;
 8 void Prime(int n){
 9     cnt=0;
10     memset(Is_Primes,0,sizeof(Is_Primes));
11     for(int i=2;i<=n;i++){
12         if(!Is_Primes[i])
13             Primes[cnt++]=i;
14         for(int j=0;j<cnt&&i*Primes[j]<n;j++){
15             Is_Primes[i*Primes[j]]=1;
16             if(i%Primes[j]==0)break;
17         }
18     }
19     
20     memset(Is_Primes,0,sizeof(Is_Primes));
21     for(int i=0;i<cnt;i++){
22         Is_Primes[Primes[i]]=1;
23     }
24 
25 }
26 int main(){
27     int a,b,n;
28     Prime(1000003);
29     while(scanf("%d%d%d",&a,&b,&n)==3&&a+b+n){
30         
31         int ans=0;
32         for(int i=0;i<1000003;i++){
33             A[i]=i*b +a;
34         //    printf("%d %d\n",A[i],i);
35             if(Is_Primes[A[i]])ans++;
36             if(ans==n){
37                 ans=A[i];
38                 break;
39             }
40         }
41         printf("%d\n",ans);
42 
43     }
44     return 0;
45 }

 

转载于:https://www.cnblogs.com/ttttttttrx/p/10279617.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值