#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; }