码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3673 1729

时间:2014-10-21 15:17:11      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

1729

Time Limit: 3 Seconds      Memory Limit: 65536 KB

1729 is the natural number following 1728 and preceding 1730. It is also known as the Hardy-Ramanujan number after a famous anecdote of the British mathematician G. H. Hardy regarding a hospital visit to the Indian mathematician Srinivasa Ramanujan. In Hardy‘s words:

I remember once going to see him when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavorable omen. "No," he replied, "it is a very interesting number; it is the smallest number expressible as the sum of two (positive) cubes in two different ways."

The two different ways are these: 1729 = 13 + 123 = 93 + 103

Now your task is to count how many ways a positive number can be expressible as the sum of two positive cubes in. All the numbers in this task can be expressible as the sum of two positive cubes in at least one way.

Input

There‘re nearly 20,000 cases. Each case is a positive integer in a single line. And all these numbers are greater than 1 and less than 264.

Output

Please refer to the sample output. For each case, you should output a line. First the number of ways n. Then followed by n pairs of integer, (ai,bi), indicating a way the given number can be expressible as the sum of ai‘s cube and bi‘s. (aibi, and a1< a2< ...< an)

Sample Input

9
4104
2622104000
21131226514944
48988659276962496

Sample Output

1 (1,2)
2 (2,16) (9,15)
3 (600,1340) (678,1322) (1020,1160)
4 (1539,27645) (8664,27360) (11772,26916) (17176,25232)
5 (38787,365757) (107839,362753) (205292,342952) (221424,336588) (231518,331954)

Hint

Although most numbers cannot be expressible as the sum of two positive cubes, the vast majority of numbers in this task can be expressible as the sum of two positive cubes in two or more ways. 

 

  1 #include<iostream>
  2 #include<stdio.h>
  3 #include<cstring>
  4 #include<math.h>
  5 #include<cstdlib>
  6 #include<algorithm>
  7 using namespace std;
  8 typedef unsigned long long LL;
  9 const int maxn = 2642246+2;
 10 
 11 struct node
 12 {
 13     LL x,y;
 14 } tom[10002];
 15 int tlen;
 16 LL prime[192728];
 17 int len;
 18 bool s[maxn];
 19 void init()
 20 {
 21     memset(s,false,sizeof(s));
 22     len = 0;
 23     for(int i=2; i<maxn; i++)
 24         if(s[i]==false)
 25         {
 26             prime[++len]=i;
 27             for(int j=i+i; j<maxn; j=j+i)
 28                 s[j]=true;
 29         }
 30 }
 31 LL fac[5001],num[5001];
 32 int flen;
 33 void Euler(LL n)
 34 {
 35     int i,count;
 36     flen = 0;
 37     for(i=1; prime[i]*prime[i]<=n; i++)
 38     {
 39         if(n%prime[i]==0)
 40         {
 41             count = 0;
 42             while(n%prime[i]==0)
 43             {
 44                 n=n/prime[i];
 45                 count++;
 46             }
 47             fac[++flen]=prime[i];
 48             num[flen]=count;
 49         }
 50     }
 51     if(n!=1)
 52     {
 53         fac[++flen]=n;
 54         num[flen]=1;
 55     }
 56 }
 57 
 58 LL Q[50050];
 59 int qlen;
 60 void solve()
 61 {
 62     Q[0]=1;
 63     qlen = 0;
 64     for(int i=1; i<=flen; i++)
 65     {
 66         int k;
 67         int s=0;
 68         for(int j=1; j<=num[i]; j++)
 69         {
 70             k = qlen;
 71             for(; s<=k; s++)
 72                 Q[++qlen]=Q[s]*fac[i];
 73         }
 74     }
 75 }
 76 int main()
 77 {
 78     LL n;
 79     int T=0;
 80     init();
 81     while(scanf("%llu",&n)>0)
 82     {
 83         Euler(n);
 84         solve();
 85         sort(Q+1,Q+1+qlen);
 86         tlen=0;
 87         int NUM=0;
 88         for(int i=1; i<=qlen; i++)
 89         {
 90             LL y = (Q[i]*Q[i]-n/Q[i])/3;
 91             LL x = Q[i];
 92             if(x*x>=4*y)
 93             {
 94                 LL ss = (LL)sqrt((x*x-4*y)*1.0);
 95                 LL ans1 = (x-ss)/2;
 96                 LL ans2 = (x+ss)/2;
 97                 if(ans1==0||ans2==0)continue;
 98                 if(ans1*ans1*ans1+ans2*ans2*ans2==n)
 99                 {
100                     tom[++tlen].x=ans1;
101                     tom[tlen].y=ans2;
102                     NUM++;
103                 }
104             }
105         }
106         printf("%d",NUM);
107         for(int i=1; i<=tlen; i++)
108             printf(" (%llu,%llu)",tom[i].x,tom[i].y);
109         printf("\n");
110     }
111     return 0;
112 }

 

zoj 3673 1729

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/tom987690183/p/4040248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!