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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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. ...

  4. 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: ...

  5. 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 ...

  6. 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 ...

  7. The Ninth Hunan Collegiate Programming Contest (2013) Problem C

    Problem C Character Recognition? Write a program that recognizes characters. Don't worry, because yo ...

  8. 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 ...

  9. German Collegiate Programming Contest 2013:E

    数值计算: 这种积分的计算方法很好,学习一下! 代码: #include <iostream> #include <cmath> using namespace std; ; ...

随机推荐

  1. (转帖)BootStrap入门教程 (二)

    上讲回顾:Bootstrap的手脚架(Scaffolding)提供了固定(fixed)和流式(fluid)两种布局,它同时建立了一个宽达940px和12列的格网系统. 基于手脚架(Scaffoldin ...

  2. session_write_close()

    功能: 结束当前的session 操作 保存session 数据  说的很明白了, 当脚本请求没有调用session_write_close(); 时虽然 session  的数据是存储住了.但是 s ...

  3. 【控件扩展】带圆角、边框、渐变的panel

    下载地址:  http://files.cnblogs.com/chengulv/custompanel_demo.zip using System; namespace LC.Fun { /// & ...

  4. <limits.h>和<float.h>

    头文件<limits.h>中定义了用于表示整类型大小的常量.以下所列的值是可接受的最小值,实际系统中可能有更大的值. CHAR_BIT char类型的位数 CHAR_MAX UCHAR_M ...

  5. LDAP过滤器使用说明(用户、组和容器的默认 LDAP 过滤器和属性)

    说明来源:http://docs.oracle.com/html/E35191_01/ldap-filters-attrs-users.html#ldap-filters-attributes-use ...

  6. wpa_supplicant移植

    移植openssl-0.9.8za cp ../wpa_supplicant-2.5/patches/openssl-0.9.8za-tls-extensions.patch .patch -p1 & ...

  7. 为什么要用VisualSVN Server,而不用Subversion?

    为什么要用VisualSVN Server,而不用Subversion? [SVN 服务器的选择] - 摘自网络 http://www.cnblogs.com/haoliansheng/archive ...

  8. Linux下diff打补丁方法

    tar zxvf php-5.2.14.tar.gz gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1

  9. C#学习笔记五: C#3.0Lambda表达式及Linq解析

    最早使用到Lambda表达式是因为一个需求:如果一个数组是:int[] s = new int[]{1,3,5,9,14,16,22};例如只想要这个数组中小于15的元素然后重新组装成一个数组或者直接 ...

  10. java 中文 乱码 问号

    在基于Java的编程中,经常会碰到汉字的处里及显示的问题,比如一大堆乱码或问号. 这是因为JAVA中默认的编码方式是UNICODE,而中国人通常使用的文件和DB都是基于GB2312或者BIG5等编码, ...