//    i:  1,  2,  3,  4,  5,   6,  7,   8,  9,   10,  ...
// s(i): 1,  3,  4,  7,  6, 12,  8, 15, 13,  18,  ...
// s(i) = sigma(i), the sum of the divisors of i
// Develop a C++ program to output n first elements of the sequence 1, 3, 4, 7, 6, ...
#include <iostream>
using namespace std;
int i, j, k, l, m, n, s;
int main()
{
    cin >> n;
    cout << "n=" << n << endl;
    for (i = 1; i <= n; i++)   cout << i << '\t';
    cout << endl;
    for (i = 1; i <= n; i++) {
        s = 0;
        for (j = 1; j <= i; j++) {
            k = i / j;
            m = k * j;
            if (i == m)   s = s + j;
        }
        cout << s << '\t';
    }
    return 0;
}
Ideone.com - XTivZx - Online C++ Compiler & Debugging Tool
Computer Methods in Science Course
Subscribe to:
Comments (Atom)
Basic Comparison of C++ and HTML/JavaScript
Here’s a basic comparison of C++ and HTML/JavaScript for common programming concepts and simple code examples for each. This will help ...
- 
<button onclick="drawX()">Draw X</button> <!-- Button to call the 'drawX' function when clicked --> <...
 - 
Here’s a basic comparison of C++ and HTML/JavaScript for common programming concepts and simple code examples for each. This will help ...
 - 
ere's a concise comparison of the main operators in C++ and Python , focusing on syntax and behavior across key categories: ✅ 1. Arit...