http://codeforces.com/contest/293/problem/C

 1 /*
 2 http://codeforces.com/contest/293/problem/C
 3 题意:(a+b+c)^3=a^3+b^3+c^3+n,给你n的值,求多少组a,b,c是正整数的解;
 4   化解3(a+b)(a+c)(b+c)=n,a,b,c等价
 5   不妨设a<=b<=c,再设a+b=x,a+c=y,b+c=z ,则x<=y<=z;
 6   则
 7   x^3<=n/3,
 8   x*y^2<=n/3, 
 9   x*y*z=n/3;
10 */
11 #include<cstdio>
12 #include<cstring>
13 #include<cstdlib>
14 #include<iostream>
15 #include<cmath>
16 #include<algorithm>
17 using namespace std;
18 typedef long long LL;
19 typedef long double LD;
20 LL n;
21 
22 int main(){
23     while (cin>>n){
24         if (n%3){
25             cout<<0<<endl;
26             continue;
27         }
28         n/=3;
29         int up=(int)(pow((LD)n,1.0/3)+0.5);
30         int ret=0;
31         for (int i=1;i<=up;i++){
32             if (n%i) continue;
33             int limt=int(sqrt((LD)n/i)+0.5);
34 
35             for (int j=limt;j>=i;j--){
36                 if ((n/i)%j) continue;
37                 int k=n/i/j;
38                 if(i+j<=k) break;
39                 if ((i+k-j)%2 ) continue;
40                // cout<<i<<" "<<j<<" "<<k<<endl;
41                 int b=(i+k-j)/2,a=i-b,c=k-b;
42                 if (a<=0 || c<=0) continue;
43                 if (a==b){
44                     if (b==c) ret+=1;
45                     else ret+=3;
46                 }else {
47                     if (b==c) ret+=3;
48                     else if (a==c)ret+=3;
49                     else ret+=6;
50                 }
51             }
52         }
53         cout<<ret<<endl;
54     }
55 
56     return 0;
57 }
View Code

相关文章:

猜你喜欢
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案