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. (ai≤ bi, and a1a2<
...< 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.

题意比較简单,就不解释了

这题还真是弄了好久,再加上犯的各种小错误,可是最终算是搞出来了,不easy啊。。。

思路:要求满足的m=a3+b3=(a+b)(a2-ab+b2)的(a,b)组合。

令t=a+b,则t一定是m的约数,所以应枚举m的全部约数。

然后能够得到

a+b=t

ab=(t2-m/t)/3=p

继而转化为a2-ta+p=0是否有正整数解就能够了。

再就是注意范围要用unsigned long long。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll unsigned long long
#define maxn 2642246//2^64次方的开立方
#define L 5000001
ll n;
ll prime[L],divi[500],e[500];
int len,len_prime,len_s;
bool flag[L] = {false};
struct node
{
ll x,y;
} s[1005]; int cmp(node x,node y)
{
return x.x<y.x;
} void init()//素数且不说,全部合数都能分解成随意素数之积
{
int i,j;
len_prime = 0;
for(i = 2; i<L; i++)
{
if(!flag[i]) prime[len_prime++] = i;//打下素数表
for(int j = 0; j<len_prime && i*prime[j]<L; j++)
{
flag[i*prime[j]] = true;//全部非素数排除
if(i%prime[j]==0) break;
}
}
} void find_div(ll m)//找出m的全部素因子
{
int i;
ll k;
len = 0;
for(i = 0; i<len_prime && prime[i]*prime[i]<=m; i++)
{
if(m%prime[i] == 0)
{
divi[len] = prime[i];//因子保存
k = 1;
m/=prime[i];
while(m%prime[i] == 0)//除尽为止
{
k++;//记录个数
m/=prime[i];
}
e[len++] = k;
}
}
if(m>1)
{
divi[len] = m;
e[len++] = 1;
}
} ll can_sqrt(ll c)//要求整数解,b^2-4*a*c必须能开出整数
{
ll r = sqrt(1.0*c);
if(r*r == c) return r;
return L;
} int judge(ll x,ll y)//看这组解是否已经存在
{
for(int i=0; i<len_s; i++)
if(s[i].x==x&&s[i].y==y)
return 1;
return 0;
} void solve(ll t)//找出解
{
ll x1,x2;
ll k = n/t;
ll r = t*t-k;
if(r>0 && r%3!=0) return ;
r/=3;
ll dis = t*t-4*r;
if(dis<0) return ;
ll c = can_sqrt(dis);
if(c == L) return;
if((t+c)%2 == 0)
{
x1 = (t+c)/2;
x2 = t-x1;
if(x1>x2) swap(x1,x2);
if(x1>0&&x1<t&&x1<maxn&&x2<maxn&&x2>0&&x2<t&&!judge(x1,x2))
{
s[len_s].x=x1;
s[len_s++].y=x2;
}
}
if((t-c)>0 && (t-c)%2 == 0)
{
x1 = (t-c)/2;
x2 = t-x1;
if(x1>x2) swap(x1,x2);
if(x1>0&&x1<t&&x1<maxn&&x2<maxn&&x2>0&&x2<t&&!judge(x1,x2))
{
s[len_s].x=x1;
s[len_s++].y=x2;
}
}
} ll ppow(ll a,ll b)
{
ll ans = 1;
while(b)
{
if(b&1) ans*=a;
b>>=1;
a*=a;
}
return ans;
} void dfs(int m,ll sum)
{
solve(sum);
if(m>=len) return ;
for(int i = 0; i<=e[m]; i++)//由个数去枚举次方,1为a,2为a^2,3为a^3,如此类推,枚举全部t
dfs(m+1,sum*ppow(divi[m],i));
} int main()
{
init();
while(~scanf("%llu",&n))
{
find_div(n);
len_s = 0;
dfs(0,1);
sort(s,s+len_s,cmp);
printf("%d",len_s);
for(int i = 0; i<len_s; i++)
printf(" (%llu,%llu)",s[i].x,s[i].y);
printf("\n");
} return 0;
}

ZOJ3673:1729的更多相关文章

  1. [BZOJ3223]Tyvj 1729 文艺平衡树

    [BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...

  2. BZOJ3223: Tyvj 1729 文艺平衡树 [splay]

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3595  Solved: 2029[Submit][Sta ...

  3. BZOJ 3223: Tyvj 1729 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3628  Solved: 2052[Submit][Sta ...

  4. zoj 3673 1729

    1729 Time Limit: 3 Seconds      Memory Limit: 65536 KB 1729 is the natural number following 1728 and ...

  5. bzoj 3223/tyvj 1729 文艺平衡树 splay tree

    原题链接:http://www.tyvj.cn/p/1729 这道题以前用c语言写的splay tree水过了.. 现在接触了c++重写一遍... 只涉及区间翻转,由于没有删除操作故不带垃圾回收,具体 ...

  6. hdoj 1729 Stone Games(SG函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1729 看了题目感觉像Nim,但是有范围限制,有点不知道SG函数该怎么写 看了题解,最后才明白该怎么去理 ...

  7. bzoj3223 Tyvj 1729 文艺平衡树(Splay Tree+区间翻转)

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2202  Solved: 1226[Submit][Sta ...

  8. BZOJ 3223: Tyvj 1729 文艺平衡树(splay)

    速度居然进前十了...第八... splay, 区间翻转,用一个类似线段树的lazy标记表示是否翻转 ------------------------------------------------- ...

  9. 3223: Tyvj 1729 文艺平衡树

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1347  Solved: 724[Submit][Stat ...

随机推荐

  1. dp入门题目

    本文文旨,如题... 转载请注明出处... HDOJ 1176 免费馅饼 http://acm.hdu.edu.cn/showproblem.php?pid=1176 类似数塔,从底往上推,每次都是从 ...

  2. centos7 PDI(Kettle)安装

    kettle介绍 PDI(Kettle)是一种开源的 ETL 解决方案,书中介绍了如何使用PDI来实现数据的剖析.清洗.校验.抽取.转换.加载等各类常见的ETL类工作. 除了ODS/DW类比较大型的应 ...

  3. 更改MyEclipse中的src目录的浏览方式

    看到这个标题,有人可能不会明白,这里先看张图: 右边的图就是我们要更改的样子,有的时候我们做项目需要看下目录的层次,于是使用了Navigator的那个视图,其实常用的这种包视图也可以变成那种样式. 这 ...

  4. 一步一步学习IdentityServer4 (2) 开始一个简单的事例

    前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...

  5. Two Seals codeforces 837c

    Two Seals 一个矩形a*b,若干子矩形,子矩形中选2个,不重叠能覆盖最大 思路: 枚举: 代码: #include <cstdio> #include <cstring> ...

  6. 【51nod】1742 开心的小Q

    题解 我们由于莫比乌斯函数如果有平方数因子就是0,那么我们可以列出这样的式子 \(\sum_{i = 1}^{n} \sum_{d|i} (1 - |\mu(d)|)\) 然后枚举倍数 \(\sum_ ...

  7. Loadrunner上传文件解决办法(大文件)

    Loadrunner上传文件解决办法(大文件) 最近再做一个跟海量存储相关的项目测试,需要通过LR模拟用户大量上传和下载文件,请求是Rest或Soap,同时还要模拟多种大小尺寸不一的文件 通常情况下, ...

  8. JS 如何准确获取当前页面URL网址信息

    在WEB开发中,时常会用到javascript来获取当前页面的url网址信息,在这里是一些获取url信息的小总结. 下面我们举例一个URL,然后获得它的各个组成部分:http://i.cnblogs. ...

  9. Linux下安装Zookeeper

    Zookeeper是一个协调服务,可以用它来作为配置维护.名字服务.分布式部署: 下面,我来分享一下在Linux下安装Zookeeper的整个步骤,让大家少走弯路. 一.Zookeeper下载 [ro ...

  10. linux查找文件或目录命令

    inux查找文件或目录命令,前提:知道文件或者目录的具体名字,例如:sphinx.conf find 查找  find / -name dirname  查找目录 find -name filenam ...