The Ninth Hunan Collegiate Programming Contest (2013) Problem J
Problem J
Joking with Fermat's Last Theorem
Fermat's Last Theorem: no three positive integers a, b, and c can satisfy the equation an + bn = cn for any integer value of n greater than two.
From the theorem, we know that a3 + b3 = c3 has no positive integer solution.
However, we can make a joke: find solutions of a3 + b3 = c3. For example 43 + 93 = 793, so a=4, b=9, c=79 is a solution.
Given two integers x and y, find the number of solutions where x<=a,b,c<=y.
Input
There will be at most 10 test cases. Each test case contains a single line: x, y (1<=x<=y<=108).
Output
For each test case, print the number of solutions.
Sample Input
1 10
1 20
123 456789
Output for the Sample Input
Case 1: 0
Case 2: 2
Case 3: 16
The Ninth Hunan Collegiate Programming Contest (2013) Problemsetter: Rujia Liu Special Thanks: Md. Mahbubul Hasan, Feng Chen
这道题有一个突破口,就是a, b <=1000 ,这样子算法就变成了 O(1000*1000)。
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
LL N_3[] ;
int x , y ;
void init(){
for(int i=;i<=;i++)
N_3[i]=i*i*i ;
// cout<<N_3[1000]<<endl ;
}
int calc(){
int a_up ,b_up ,c ,sum ,ans= ;
a_up=Min(y,) ;
b_up=Min(y,) ;
for(int a=x;a<=a_up;a++)
for(int b=x;b<=b_up;b++){
sum=N_3[a]+N_3[b] ;
if(sum%==){
int c=sum/ ;
if(x<=c&&c<=y)
ans++ ;
}
}
return ans ;
}
int main(){
init() ;
int k= ;
while(scanf("%d%d",&x,&y)!=EOF){
printf("Case %d: %d\n",k++ ,calc()) ;
}
return ;
}
The Ninth Hunan Collegiate Programming Contest (2013) Problem J的更多相关文章
- The Ninth Hunan Collegiate Programming Contest (2013) Problem A
Problem A Almost Palindrome Given a line of text, find the longest almost-palindrome substring. A st ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem F
Problem F Funny Car Racing There is a funny car racing in a city with n junctions and m directed roa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem H
Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem I
Problem I Interesting Calculator There is an interesting calculator. It has 3 rows of button. Row 1: ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem G
Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem L
Problem L Last Blood In many programming contests, special prizes are given to teams who solved a pa ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem C
Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...
- The 2019 China Collegiate Programming Contest Harbin Site J. Justifying the Conjecture
链接: https://codeforces.com/gym/102394/problem/J 题意: The great mathematician DreamGrid proposes a con ...
- German Collegiate Programming Contest 2013:E
数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...
随机推荐
- 【jmeter】测试报告优化<二>
如果按JMeter默认设置,生成报告如下: 从上图可以看出,结果信息比较简单,对于运行成功的case,还可以将就用着.但对于跑失败的case,就只有一行assert错误信息.(信息量太少了,比较难找到 ...
- 【linux】Cache和Buffer的区别
- vs2010 release 模式加了断点,跑代码无法跟踪,解决方法
纯跑代码,不是附加进程调试. 打开不能调试的类库项目属性页面→切换到生成选项卡→点击高级按钮→将调试信息一项设置 将“调试信息”设置为“pdb-only”. 我是按图上的设置就正常了. -- 201 ...
- Window下Nexus私服搭建
项目组大部分人员不能访问maven的central repository,因此在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到这台私服上 环境是:nexus-2.1.1.mav ...
- C#中WebService 的 Timer定时器过段时间后自动停止运行
我用.net做的一个Timer定时器,定时获取短信并给予回复,但大概过了十几个小时以后,Timer定时器会自动停止,再发送短信就不能收到回复,需要在服务器中重新运行定时器才可以,请教各位! 我是在.n ...
- hadoop mapred-queue-acls 配置(转)
hadoop作业提交时可以指定相应的队列,例如:-Dmapred.job.queue.name=queue2通过对mapred-queue-acls.xml和mapred-site.xml配置可以对不 ...
- C#学习笔记二: C#类型详解
前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...
- Scala第二章学习笔记
最基本的练习~: 使用伴生对象: object holder{ class Foo{ private var x = 5} object Foo{def im_in_yr_foo(f: Foo) = ...
- 2016 Multi-University Training Contest 5 ATM Mechine
ATM Mechine 本文转自:http://blog.csdn.net/queuelovestack/article/details/52096337 题意: 这题的意思还是比较费解的 Alice ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...