#include<iostream> usingnamespace std; int N, ans; intmain() { cin >> N; while (N--) { for (int i = 1; i * i <= N; i++) { if (N % i == 0) { ans++; if (i * i != N) ans++; } } } cout << ans << endl; return0; }
Another solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream> usingnamespace std; int n, ans; intmain() { cin >> n; for(int i = 1; i < n; i++) { ans += n / i; if(n % i == 0) ans--; } cout << ans << endl; return0; }