zoj 3673 1729
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. (ai≤ bi, 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 ;
}
zoj 3673 1729的更多相关文章
- ZOJ Monthly, November 2012
A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...
- zoj 1729 Hidden Password
Hidden Passwordhttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=729 Time Limit: 2 Seconds ...
- ZOJ 1729 Hidden Password (字符串最小表示)
以前听过,不知道是什么,其实就是字符串首尾相连成一个环,n种切法求一个字典序最小的表示. 朴素算法大家都懂.O(n)的算法代码非常简单,最主要的思想是失配的时候尽可能大的移动指针. 另外附上一个不错的 ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- [BZOJ3223]Tyvj 1729 文艺平衡树
[BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- chineseChess
最近学习了chineseChess的Qt实现,把一些东西总结一下: 实现功能: 1.人人对战 2.人机对战 3.网络版 一.基础性工作:(人人对战) 1.棋盘和棋子的绘制(QPinter,drawLi ...
- 详解NTFS文件系统
一.分析NTFS文件系统的结构 当用户将硬盘的一个分区格式化为NTFS分区时,就建立了一个NTFS文件系统.NTFS文件系统同FAT32文件系统一样,也是用“簇”为存储单位,一个文件总是占用一个或多个 ...
- C#编码标准
一.命名约定 1.PascalCasting PascalCasing 每一个单词第一个字母大写,其余字母均小写.例如:FileAccess,ArraySegment等. 除了参数.变量.常量外,所有 ...
- 【iCore3 双核心板_FPGA】例程十:锁相环实验——锁相环使用
实验指导书及代码包下载: http://pan.baidu.com/s/1boeODjx iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- jquery 绑定事件的方法
jQuery中提供了四种绑定事件的方法,分别是bind.live.delegate.on,对应的解除监听的函数分别是unbind.die.undelegate.off: 一.on()方法(首选方法) ...
- Array与ArrayBuffer
一.概述 二:Array使用 1.建立方式三种(数组里可以有不同的数据类型) 2.Array的简单使用 三:ArrayBuffer的简单使用 1.ArrayBuffer建立 导包 2.添加元素(+=) ...
- Visual Studio中编写C程序
相信很多科班出身的程序猿和我一样,第一个接触到的编程语言是C语言,第一个写的程序是“Hello World!”. 对于一个.Net程序猿,VS肯定是个非常熟悉的工具,但是如何使用VS编写一个C语言程序 ...
- 《Linux内核分析》第五周 扒开系统调用的三层皮(下)
[刘蔚然 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] WEEK FIVE( ...
- MySQL中文全文检索
一.概述 MySQL全文检索是利用查询关键字和查询列内容之间的相关度进行检索,可以利用全文索引来提高匹配的速度. 二.语法 MATCH (col1,col2,...) AGAINS ...
- LeetCode Maximum Size Subarray Sum Equals k
原题链接在这里:https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/ 题目: Given an array nums an ...