#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second int get(int x) { //printf("liczba %d ", x); int res = 1, rmv = 2; if (x%2 == 0) rmv++; for (int d = 2; d*d <= x; d++) if (x%d == 0) { int cnt = 0; while (x%d == 0) { x /= d; cnt++; } res *= cnt+1; } if (x > 1) res *= 2; //printf("ma %d czynnikow\n", res); return max(res - rmv, 0); } int main() { int n, res = 0; scanf("%d", &n); for (int a = 1; a*a <= n; a++) if (n%a == 0) { res += get(n/a-1); if (n != a*a) res += get(a-1); } printf("%d\n", res); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for (int i = (a); i <= (b); ++i) #define REPD(i,a,b) for (int i = (a); i >= (b); --i) #define FORI(i,n) REP(i,1,n) #define FOR(i,n) REP(i,0,int(n)-1) #define mp make_pair #define pb push_back #define pii pair<int,int> #define vi vector<int> #define ll long long #define SZ(x) int((x).size()) #define DBG(v) cerr << #v << " = " << (v) << endl; #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define fi first #define se second int get(int x) { //printf("liczba %d ", x); int res = 1, rmv = 2; if (x%2 == 0) rmv++; for (int d = 2; d*d <= x; d++) if (x%d == 0) { int cnt = 0; while (x%d == 0) { x /= d; cnt++; } res *= cnt+1; } if (x > 1) res *= 2; //printf("ma %d czynnikow\n", res); return max(res - rmv, 0); } int main() { int n, res = 0; scanf("%d", &n); for (int a = 1; a*a <= n; a++) if (n%a == 0) { res += get(n/a-1); if (n != a*a) res += get(a-1); } printf("%d\n", res); return 0; } |