{
  "question_id": 876769,
  "question_title": "求前n个素数之和",
  "question_content": "题目描述\n求前n个素数的和。 \n例如，前5个素数是2、3、5、7、11，它们的和是28。 \n输入\n一个整数n，1<=n<=1000。 \n输出\n前n个素数的和 \n样例输入\n5\n样例输出\n28\n提示\n第1000个素数是7919。\n",
  "difficulty": "中等",
  "answer_id": 1011802,
  "answer_content": "你的a是数组，a++是非法的\n\n```\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int n,i,j,sum,a;\n    cin>>n;\n\n    a = 0;\n    i = 2;\n    sum=0;\n    while(a<n){\n        for(j=2;j<=i;j++)\n            if(i%j == 0)\n                break;\n        if(j == i)\n        {\n            sum += i;\n            ++a;\n        }\n        ++i;\n    }\n    cout<<sum;\n}\n```",
  "tag_name": "c++",
  "cpp": "#include <iostream>\nusing namespace std;\nint main()\n{\n\tint n,i,j,sum,a;\n\tcin>>n;\n\ta = 0;\n\ti = 2;\n\tsum=0;\n\twhile(a<n){\n\t\tfor(j=2;j<=i;j++)\n\t\t\tif(i%j == 0)\n\t\t\t\tbreak;\n\t\tif(j == i)\n\t\t{\n\t\t\tsum += i;\n\t\t\t++a;\n\t\t}\n\t\t++i;\n\t}\n\tcout<<sum;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600469943",
  "status": 1,
  "keywords": "算法高阶,数论算法,素数的测试,算法问题选编",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/39.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "qq_31270229"
}