Zoj 3673 1729

Source: Internet
Author: User
1729 Time Limit: 3 seconds memory limit: 65536 KB

1729 is the natural number following 1728 and preceding 1730. It is also known asHard-Ramanujan numberAfter a famous anecdote of the British mathematicianG. H. HardRegarding a hospital visit to the Indian mathematicianSrinivasa Ramanujan. In Hard'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 got ed 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 shocould output a line. First the number of waysN. Then followedNPairs of integer ,(AI,BI), indicating a way the given number can be expressible as the sumAI's cube andBI's .(AI ≤BI, andA1 <A2 <... <AN)

Sample Input
9410426221040002113122651494448988659276962496
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.