#include <bits/stdc++.h> using namespace std; vector<int> get_divisors(int n){ vector<int> results; for(int i = 1; i * i <= n; i++){ if(n % i == 0){ if(i * i != n){ results.push_back(i); results.push_back(n/i); } else{ results.push_back(i); } } } return results; } int main(){ int n; cin>>n; if(n == 1){ cout<<0<<endl; return 0; } vector<int> divs = get_divisors(n); int sum = 0; for(int div : divs){ int s = n/div - 1; if(s == 1 || s == 0 || s == 2){ continue; } vector<int> div2 = get_divisors(s); sum += div2.size() - 2; if(s % 2 == 0){ sum -= 1; } } cout<<sum<<endl; }
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 | #include <bits/stdc++.h> using namespace std; vector<int> get_divisors(int n){ vector<int> results; for(int i = 1; i * i <= n; i++){ if(n % i == 0){ if(i * i != n){ results.push_back(i); results.push_back(n/i); } else{ results.push_back(i); } } } return results; } int main(){ int n; cin>>n; if(n == 1){ cout<<0<<endl; return 0; } vector<int> divs = get_divisors(n); int sum = 0; for(int div : divs){ int s = n/div - 1; if(s == 1 || s == 0 || s == 2){ continue; } vector<int> div2 = get_divisors(s); sum += div2.size() - 2; if(s % 2 == 0){ sum -= 1; } } cout<<sum<<endl; } |