#include <iostream> #include <cassert> using namespace std; int comb(int d, int m) { int answer = 0; for (int e=2;e*e<=m;e++) { if (m%e==0) { int f = m/e; if (d*e<d*e*(f-1)) { answer++; //cout<<d<<" "<<d*e<<" "<<d*e*(f-1)<<endl; //assert(d<d*e); //assert(d*e<d*e*(m/e-1)); } if (f!=e && d*f<d*f*(e-1)) { answer++; //cout<<d<<" "<<d*f<<" "<<d*f*(e-1)<<endl; } } } return answer; } int solve(int n) { int answer = 0; int t=0; for (int d=1;d*d<=n;d++) { if (n%d==0){ answer += comb(d,n/d-1); if (d!=n/d) answer += comb(n/d,d-1); } } //cout << answer; //cout << " " <<t<<endl; return answer; } int main() { int n; cin >> n; cout << solve(n); 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 45 | #include <iostream> #include <cassert> using namespace std; int comb(int d, int m) { int answer = 0; for (int e=2;e*e<=m;e++) { if (m%e==0) { int f = m/e; if (d*e<d*e*(f-1)) { answer++; //cout<<d<<" "<<d*e<<" "<<d*e*(f-1)<<endl; //assert(d<d*e); //assert(d*e<d*e*(m/e-1)); } if (f!=e && d*f<d*f*(e-1)) { answer++; //cout<<d<<" "<<d*f<<" "<<d*f*(e-1)<<endl; } } } return answer; } int solve(int n) { int answer = 0; int t=0; for (int d=1;d*d<=n;d++) { if (n%d==0){ answer += comb(d,n/d-1); if (d!=n/d) answer += comb(n/d,d-1); } } //cout << answer; //cout << " " <<t<<endl; return answer; } int main() { int n; cin >> n; cout << solve(n); return 0; } |