Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16733   Accepted: 8427 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing…
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13636   Accepted: 6808 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing…
题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16803   Accepted: 8474 Description If a and d are relatively prime positive integers, t…
http://poj.org/problem?id=3006 #include <cstdio> using namespace std; bool pm[1000002]; bool usd[1000002]; bool judge(int x) { if(usd[x])return pm[x]; usd[x] = true; if(x == 2) return pm[x] = true; if(((x & 1) == 0) || (x < 2))return pm[x] =…
题目大意:a和d是两个互质的数,则序列a,a+d,a+2d,a+3d,a+4d ...... a+nd 中有无穷多个素数,给出a和d,找出序列中的第n个素数 #include <cstdio> int isPrime(int n) { || (n != && n % == )) ; ; i*i <= n; ++i) ) ; ; } int main() { int a,d,n,cun,temp; while(scanf("%d %d %d",&…
简单的暴力筛法就可. #include <iostream> #include <cstring> #include <cmath> #include <cctype> #include <cstdio> #include <cmath> #include <algorithm> #include <numeric> using namespace std; , M = ; bool is[N]; int pr…
题意 给出a d n    给出数列 a,a+d,a+2d,a+3d......a+kd 问第n个数是几 保证答案不溢出 直接线性筛模拟即可 #include<cstdio> #include<cstring> using namespace std; ]; ]; ]; int cnt; void Prime(int n){ cnt=; memset(Is_Primes,,sizeof(Is_Primes)); ;i<=n;i++){ if(!Is_Primes[i]) Pr…
http://poj.org/problem?id=3006 #include<stdio.h> #include<math.h> int is_prime(int n) { int i,m; ) ; m = sqrt(n); ; i <= m; i ++) { ) ; } ; } int main() { int a,d,n,i; while(~scanf("%d%d%d",&a,&d,&n)) { ; &&d==…
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#status//I/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="font-family:Verdana,Arial,sans-serif; f…
poj3006 Dirichlet's Theorem on Arithmetic Progressions 很显然这是一题有关于素数的题目. 注意数据的范围,爆搜超时无误. 这里要用到筛选法求素数. 筛选法求素数的大概思路是: 如果a这个数是一个质数,则n*a不是质数.(年轻的孩子们不要纠结于判断a是否为素数) 用一个数组实现就是: memset(prime,true,sizeof(prime)); if (prime[i]) prime[i*j]=false; 部分程序如下: const m…