#include <iostream>
#include <cmath>
#define FOR(a,b,e) for(int a=(b);a<=(e);++a)
using namespace std;
int n,b,c,sqrtn,n1,sqrtn1,y;
long long res=0;
void inline checkB(int a, int x) {
y=(n1/x)-1;
if(y>=2) {
b=a*x;
c=b*y;
if(a+b+c==n) {
//cout<<a<<" "<<b<<" "<<c<<endl;
++res;
}
}
}
void inline checkA(int a) {
n1=n/a-1;
sqrtn1=floor(sqrt(n1));
FOR(x,2,sqrtn1) {
if(n1%x)
continue;
checkB(a,x);
if(x*x<n1)
checkB(a,n1/x);
}
}
int main() {
cin>>n;
sqrtn=floor(sqrt(n));
FOR(a,1,sqrtn) {
if(n%a)
continue;
checkA(a);
if(a*a<n)
checkA(n/a);
}
cout<<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 45 46 | #include <iostream> #include <cmath> #define FOR(a,b,e) for(int a=(b);a<=(e);++a) using namespace std; int n,b,c,sqrtn,n1,sqrtn1,y; long long res=0; void inline checkB(int a, int x) { y=(n1/x)-1; if(y>=2) { b=a*x; c=b*y; if(a+b+c==n) { //cout<<a<<" "<<b<<" "<<c<<endl; ++res; } } } void inline checkA(int a) { n1=n/a-1; sqrtn1=floor(sqrt(n1)); FOR(x,2,sqrtn1) { if(n1%x) continue; checkB(a,x); if(x*x<n1) checkB(a,n1/x); } } int main() { cin>>n; sqrtn=floor(sqrt(n)); FOR(a,1,sqrtn) { if(n%a) continue; checkA(a); if(a*a<n) checkA(n/a); } cout<<res; return 0; } |
English