博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ3673:1729
阅读量:5834 次
发布时间:2019-06-18

本文共 3174 字,大约阅读时间需要 10 分钟。

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

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.

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

这题还真是弄了好久,再加上犯的各种小错误,可是最终算是搞出来了,不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 
#include
#include
#include
using namespace std;#define ll unsigned long long#define maxn 2642246//2^64次方的开立方#define L 5000001ll 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
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
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
0&&x2
0 && (t-c)%2 == 0) { x1 = (t-c)/2; x2 = t-x1; if(x1>x2) swap(x1,x2); if(x1>0&&x1
0&&x2
>=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

转载地址:http://hzucx.baihongyu.com/

你可能感兴趣的文章
CSS——(2)与标准流盒模型
查看>>
C#中的Marshal
查看>>
linux命令:ls
查看>>
Using RequireJS in AngularJS Applications
查看>>
【SAP HANA】关于SAP HANA中带层次结构的计算视图Cacultation View创建、激活状况下在系统中生成对象的研究...
查看>>
CentOS 7 装vim遇到的问题和解决方法
查看>>
【ros】Create a ROS package:package dependencies报错
查看>>
通过容器编排和服务网格来改进Java微服务的可测性
查看>>
使用《Deep Image Prior》来做图像复原
查看>>
Linux基础命令---rmdir
查看>>
Squid 反向代理服务器配置
查看>>
Java I/O操作
查看>>
Tomcat性能调优
查看>>
Android自学--一篇文章基本掌握所有的常用View组件
查看>>
灰度图像和彩色图像
查看>>
FreeMarker-Built-ins for strings
查看>>
argparse - 命令行选项与参数解析(转)
查看>>
修改上一篇文章的node.js代码,支持默认页及支持中文
查看>>
我理想中的前端工作流
查看>>
Chrome 广告屏蔽功能不影响浏览器性能
查看>>