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. webstorm配置nodejs,bower,git,github

    一,配置nodejs第一大步,首先安装nodejs,安装nodejs的时候,我们需要把所有的组建勾选上,然后选择add to path,这一步会自动帮我们配置环境变量,安装完成后,打开cmd,输入no ...

  2. 剑指offer系列45---和为s的两个数字

    [题目]输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S, package com.exe9.offer; /** * [题目]输入一个递增排序的数组和一个数字S,在数组中 ...

  3. FIR系统的递归与非递归实现

    首先,因为FIR的脉冲响应是有限长,所以总是可以非递归实现的: 其次,也可以用递归系统来实现它. 以滑动平均做例子,最直观的想法就是,每次来一个新的值,丢掉最老的,加上最新的: y[n]=y[n-1] ...

  4. Python 创建和发布安装函数模块

    1. create dir "nester" under C:\Users\eric\AppData\Local\Programs\Python\Python35-32\ 2. c ...

  5. IOS开发之自定义系统弹出键盘上方的view(转载)

    这篇文章解决的一个开发中的实际问题就是:当弹出键盘时,自定义键盘上方的view.目前就我的经验来看,有两种解决方法.一个就是利用UITextField或者UITextView的inputAccesso ...

  6. 黄聪:MYSQL5.6缓存性能优化my.ini文件配置方案

    使用MYSQL版本:5.6 [client] …… default-character-set=gbk default-storage-engine=MYISAM max_connections=10 ...

  7. hdu1358 Period

    首先给个博客:http://blog.csdn.net/lttree/article/details/20732385 感觉他说的很好,尤其是引用的那个博客,清晰的说明了循环节的两个公式. http: ...

  8. window下安装oracle数据库

    Oracle 11g安装 1.解压下载的包,然后进入包内,点击setup.exe开始安装 . 2.出现如下:一般把那个小对勾取消,点击下一步进行, 弹出下图这个后点‘是’ 3.下图后,选择创建和配置数 ...

  9. ylbtech-Unitity-CS:Hello world

    ylbtech-Unitity-CS:Hello world 1.A,效果图返回顶部   1.B,源代码返回顶部 1.B.1,Hello1.cs public class Hello1 { publi ...

  10. http请求的referer属性

    HTTP Referer是header的一部分,当浏览器向web服务器发送请求的时候,一般会带上Referer,告诉服务器我是从哪个页面链接过来的,服务器籍此可以获得一些信息用于处理.比如从我主页上链 ...