标签:
#include <iostream> using namespace std; //编一个程序求质数的和例如F(7) = 2 + 3 + 5 + 7 + 11 + 13 + 17 = 58. int Grial(int n) { int *b = new int[n]; int k = 0; b[k++] = 2; int i = 2; int j; int count = b[0]; while (i++) { if (k == n)break; for (j = 0; j*j < k; j++) { if (i%b[j] == 0)break; } if (j*j >= k) { count += i; b[k++] = i; } } return count; } int main() { cout<<Grial(7)<<endl; return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/liuhuiyan_2014/article/details/47360943