连接

codeforces 299E Cube Problem

Cube Problem

Time Limit:2000MS  

Memory Limit:262144KB    

64bit IO Format:%I64d & %I64u Submit   Status   Practice  

CodeForces 299E

Description Yaroslav, Andrey and Roman love playing cubes. Sometimes they get together and play cubes for hours and hours!

Today they got together again and they are playing cubes. Yaroslav took unit cubes and composed them into an a?×?a?×?a cube, Andrey made a b?×?b?×?b cube and Roman made a c?×?c?×?c cube. After that the game was finished and the guys left. But later, Vitaly entered the room. He saw the cubes and wanted to make a cube as well. But what size should the cube be? Of course it should be a large cube with the side of length a?+?b?+?c. Besides, Vitaly decided to decompose the cubes built by Yaroslav, Andrey and Roman and compose his own large cube out of them. However, it turned out that the unit cubes he got from destroying the three cubes just weren't enough to make a large cube. We know that Vitaly was short of exactly n cubes. Vitaly got upset, demolished everything and left. As he was leaving, he met Petya and told him that there had been three cubes in the room and that he needed another n unit cubes to make his own large cube.

Petya entered the room and saw the messily scattered cubes. He wanted to make it neat and orderly again. But he only knows that there had been three cubes, made of small unit cubes and that Vitaly needed n more unit cubes to make a large one! Help Petya understand, how many ways of sizes a, b, c are there to restore Yaroslav's, Andrey's and Roman's cubes.

Input The single line of the input contains integer n (1?≤?n?≤?10^14). We know that all numbers a, b, c are positive integers.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output In the single line print the required number of ways. If it turns out that there isn't a single way of suitable sizes of a, b, c, print 0.

Sample Input

Input 24

Output 1

Input 648

Output 7

Input 5

Output 0

Input 93163582512000

Output 39090

 

 

 

 

/*

n数量级为10^14

题意:(a+b+c)^3-(a^3+b^3+c^3)=n;  化简即为:3*(a+b)*(b+c)*(c+a)=n;

显然n必须mod 3   即为(a+b)*(b+c)*(c+a)=n;(n/=3)

令i=(a+b);j=(b+c);k=(c+a);x^3=n;(i,j,k可以构成三角形!!)

枚举i(1-x);

令a=n/i;(n%i==0)

i+j>k;(1)

j*k=a;(2)

两式消k得:(j+i/2)^2>a+(i/2)^2;  令h=sqrt(a+i/2)^2)-i/2;//核心!!!!

由(2)知j*j<a(j<k)即为j<sqrt(a);

 

故j枚举范围为:min(i,h)-sqrt(a);

大功告成!!!

*/

 

 

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     __int64 x,n;
 8     int i,j,a,b,c,y,k,q,p,ans;
 9     scanf("%I64d",&n);
10     if(n%3) 
11     {
12         printf("0\n");
13         return 0;
14     }
15     n=n/3;    x=1;  ans=0;
16     while((x+1)*(x+1)*(x+1)<=n)
17         x++;    
18     for(i=2;i<=int(x);i++)
19     {
20         if(n%i) continue;
21         y=sqrt(n/i);q=(sqrt(i*i+4*n/i)-i)/2;
22         for(j=i>q?i:q;j<=y;j++)
23         {
24             k=n/i/j;
25             if(k<j) break;
26             if(n/i%j) continue;            
27             if((i+j+k)%2)continue;
28             p=(i+j+k)/2;
29             a=p-i;    b=p-j;    c=p-k;
30             if(a<1||b<1||c<1) continue;
31             if(a==b&&b==c)        ans++;
32             else if(a==b||b==c)    ans+=3;
33             else                ans+=6;
34         }
35     }
36     printf("%d\n",ans);
37     return 0;
38 }
View Code

 

posted @ 2013-08-01 21:27  朱群喜_QQ囍_海疯习习  阅读(240)  评论(0编辑  收藏  举报
Map