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; ; ...
随机推荐
- 运行ASP程序报错
错误提示: An error occurred on the server when processing the URL. Please contact the system administrat ...
- .NET导入openssl生成的公钥之BEGIN RSA PUBLIC KEY
.NET导入openssl生成的公钥之BEGIN RSA PUBLIC KEY 我得到了一个公钥,形式如下 -----BEGIN RSA PUBLIC KEY----- MIGJAoGBAMroxz3 ...
- mysql 获取设置环境变量
mysql 获取环境变量 show global variables; 获取指定环境变量 show global variables like '%timeout'; 设置环境变量 set globa ...
- js cookie操作
//写Cookie function writeCookie(name, value) { var expire = new Date(); expire.setFullYear(expire.get ...
- 解决tableView分割线左边不到边的情况
//解决tableView分割线左边不到边的情况// if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {// ...
- 【initrd】向虚拟文件系统initrd.img中添加驱动
虚拟文件系统:initrd-2.6.18-194.el5.img 希望添加网卡或SCSI等驱动 步骤: 解压initrd-2.6.18-194.el5.img: 添加*.ko文件,并修改init可执行 ...
- IntelliJ IDEA设置自动导入包
IntelliJ IDEA可以自动优化导入包,但是有多个同名的类位于不同的包时,需要自己手动使用Alt + Enter进行导入. Settings→Editor→General→Auto Import ...
- php获取一年中某一周的开始和结束时间
PHP来获取一年中的每星期的开始日期和结束日期的代码 函数get_week()通过传入参数$year年份,获取当年第一天和最后一天所在的周数,计算第一周的日期,通过循环获取每一周的第一天和最后一天的日 ...
- nodejs小问题:express不是内部或外部命令
来源:http://jingyan.baidu.com/article/922554468a3466851648f419.html 一时兴起想学习点东西,准备在heroku上部署一个Node.js的小 ...
- 【linux】之虚拟机的使用
VMware常用的配置 1.虚拟机快照设置 2.虚拟机克隆 分为链接克隆和完整克隆 链接克隆不占用过大的资源,但是主机删除之后,克隆机无法正常使用 完整克隆,占用空间资源,和主机之间互不影响 一般常用 ...