fork download
  1.  
  2. #include<bits/stdc++.h>
  3. #define ll long long int
  4. #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  5. #define print(v) for(ll printing=0;printing<v.size();printing++){cout<<v[printing]<<' ';}
  6. #define pb push_back
  7. #define f first
  8. #define s second
  9. #define mp make_pair
  10. #define Testcase long long int testcases;cin>>testcases;while(testcases--)
  11. #define gcd __gcd
  12. using namespace std;
  13.  
  14. ll value[10000001];
  15. void init(){
  16. bool marked[10000001]={false};
  17. for(ll p=2;p*p<=10000000;p++){
  18. if(!marked[p]){
  19. for(ll j=p;j<=10000000;j+=p){
  20. if(!marked[j]){
  21. value[j]=p;marked[j]=true;
  22. }
  23.  
  24. }
  25. }
  26. }
  27. for(ll i=0;i<=10000000;i++)
  28. if(!marked[i])
  29. value[i]=i;
  30. }
  31.  
  32.  
  33. int main(){
  34. fastIO;
  35. init();
  36. #ifndef ONLINE_JUDGE
  37. freopen("input.txt", "r", stdin);
  38. freopen("output.txt", "w", stdout);
  39. #endif
  40. //cout<<"val"<<value[15];
  41. ll ans[10000001];
  42. ans[0]=0;ans[1]=0;
  43. for(ll j=2;j<=10000000;j++)
  44. ans[j]=ans[j-1]+value[j];
  45. Testcase{
  46. ll n;cin>>n;
  47. cout<<ans[n]<<"\n";
  48. }
  49. return 0;
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
Success #stdin #stdout 0.2s 169672KB
stdin
4
2
3
4
10000000
stdout
2
5
7
3203714961609