标签:mat ase base col line return tom blog rip
让我们定义d?n??为:d?n??=p?n+1???p?n??,其中p?i??是第i个素数。显然有d?1??=1,且对于n>1有d?n??是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。
现给定任意正整数N
(<),请计算不超过N
的满足猜想的素数对的个数。
输入在一行给出正整数N
。
在一行中输出不超过N
的满足猜想的素数对的个数。
20
4
#include<cmath> #include<iostream> using namespace std; bool isPrime(int n) { if (n == 1 || n == 0) return false; if (n == 2) return true; int tmp = (int)sqrt((double)n); for (int i = 2; i <= tmp; i++) { if (n%i == 0) return false; } return true; } int main() { int num, count = 0; cin >> num; for (int i = 3; i <= num - 2; i++) { if (isPrime(i) && isPrime(i + 2)) count++; } cout << count << endl; return 0; }
标签:mat ase base col line return tom blog rip
原文地址:http://www.cnblogs.com/puhu/p/7662857.html