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.

题意:给一个数字N,问有多少中方法组成 a^3+b^3 = N,把每一种情况输出来。

思路:a^3+b^3 = (a^2+b^2-ab)*(a+b) 那么我们就知道(a+b)是N的一个因子。

由此枚举每一个因子。

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef unsigned long long LL;
const int maxn = +; struct node
{
LL x,y;
} tom[];
int tlen;
LL prime[];
int len;
bool s[maxn];
void init()
{
memset(s,false,sizeof(s));
len = ;
for(int i=; i<maxn; i++)
if(s[i]==false)
{
prime[++len]=i;
for(int j=i+i; j<maxn; j=j+i)
s[j]=true;
}
}
LL fac[],num[];
int flen;
void Euler(LL n)
{
int i,count;
flen = ;
for(i=; prime[i]*prime[i]<=n; i++)
{
if(n%prime[i]==)
{
count = ;
while(n%prime[i]==)
{
n=n/prime[i];
count++;
}
fac[++flen]=prime[i];
num[flen]=count;
}
}
if(n!=)
{
fac[++flen]=n;
num[flen]=;
}
} LL Q[];
int qlen;
void solve()
{
Q[]=;
qlen = ;
for(int i=; i<=flen; i++)
{
int k;
int s=;
for(int j=; j<=num[i]; j++)
{
k = qlen;
for(; s<=k; s++)
Q[++qlen]=Q[s]*fac[i];
}
}
}
int main()
{
LL n;
int T=;
init();
while(scanf("%llu",&n)>)
{
Euler(n);
solve();
sort(Q+,Q++qlen);
tlen=;
int NUM=;
for(int i=; i<=qlen; i++)
{
LL y = (Q[i]*Q[i]-n/Q[i])/;
LL x = Q[i];
if(x*x>=*y)
{
LL ss = (LL)sqrt((x*x-*y)*1.0);
LL ans1 = (x-ss)/;
LL ans2 = (x+ss)/;
if(ans1==||ans2==)continue;
if(ans1*ans1*ans1+ans2*ans2*ans2==n)
{
tom[++tlen].x=ans1;
tom[tlen].y=ans2;
NUM++;
}
}
}
printf("%d",NUM);
for(int i=; i<=tlen; i++)
printf(" (%llu,%llu)",tom[i].x,tom[i].y);
printf("\n");
}
return ;
}

最新文章

  1. [NOIP2013]华容道
  2. C++_系列自学课程_第_10_课_表达式_《C++ Primer 第四版》
  3. SpringMVC 处理异常的4种方式
  4. angularjs $q、$http 处理多个异步请求
  5. Eclipse J2EE LUNA 部署tomcat
  6. 没有VisualStudio也要HelloWorld
  7. 面向对象编程(八)——this关键字
  8. LeetCode45 Jump Game II
  9. Mars的mp3实例
  10. UML(Unified Modeling Language)同一建模语言
  11. [翻译]成为顶尖程序员应当学什么?Python、C还是Ruby?
  12. Beautiful Soup库
  13. Eeffective C++ 读书笔记( 32-38)
  14. 公共DNS推荐及dns测速
  15. [一] java8 函数式编程入门 什么是函数式编程 函数接口概念 流和收集器基本概念
  16. React-Native:解决真机调试时候Could not get BatchedBridge, make sure your bundle is packaged properly
  17. 2018-08-13 Head First OO分析设计一书略读与例子中文化
  18. 从光盘安装ubuntu系统
  19. __x__(2)0905第二天__计算机软件和硬件
  20. elasticsearch更新doc文档

热门文章

  1. 2016HUAS暑假集训题1 A-士兵队列训练问题
  2. SSH整合简单实例
  3. 从oracle数据表中读取表结构
  4. ExtJs 使用点滴 十三 在FormPanel 嵌入按钮
  5. .NET Framework (代码库、通用类型系统CTS、CLR) 简介
  6. Servlet 生命周期、工作原理
  7. 获取windows磁盘的可用空间函数
  8. blockdev命令和blkid命令
  9. centos 下建用户 shell编程
  10. float属性