fork(2) download
  1. // i: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
  2. // s(i): 1, 3, 4, 7, 6, 12, 8, 15, 13, 18, ...
  3. // s(i) = sigma(i), the sum of the divisors of i
  4. // Develop a C++ program to output n first elements of the sequence 1, 3, 4, 7, 6, ...
  5.  
  6. #include <iostream>
  7. using namespace std;
  8. int i,j,k,m,n,s;
  9. int main() {
  10. cin >> n;
  11. cout << "n=" <<n<<endl;
  12. for(i=1;i<=n;i++) cout << i <<'\t';
  13. cout << endl;
  14. for(i=1;i<=n;i++)
  15. {
  16.  
  17. s=0;
  18. for(j=1;j<=i;j++)
  19. {
  20. k=i/j;
  21. m=k*j;
  22. if(i==m)s=s+j;
  23. }
  24. cout << s <<'\t';
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 4404KB
stdin
10
stdout
n=10
1	2	3	4	5	6	7	8	9	10	
1	3	4	7	6	12	8	15	13	18