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. SharePoint 2010 最佳实践学习总结------第1章 SharePoint Foundation开发基础

    ----前言 这段时间项目出在验收阶段,不是很忙,就潜心把SharePoint学一下,不求有多深刻,初衷只是先入门再说.后续会发布一系列的学习总结.主要学习的书籍为<SharePoint2010 ...

  2. 【jmeter】Bean shell使用(二)

    上一篇Jmeter之Bean shell使用(一)简单介绍了下Jmeter中的Bean shell,本文是对上文的一个补充,主要总结下常用的几种场景和方法,相信这些基本可以涵盖大部分的需求.本节内容如 ...

  3. 清理java环境

    system32中存在3个java*.exe文件,分别是: c:/windows/system32/java.exe c:/windows/system32/javaw.exe c:/windows/ ...

  4. Spring实战4:面向切面编程

    主要内容 面向切面编程的基本知识 为POJO创建切面 使用@AspectJ注解 为AspectJ的aspects注入依赖关系 在南方没有暖气的冬天,太冷了,非常想念北方有暖气的冬天.为了取暖,很多朋友 ...

  5. Saltstack系列3:Saltstack常用模块及API

    说明 salt '*' sys.list_modules #列出当前版本支持的模块 API原理是通过调用master client模块,实例化一个LocalClient对象,再调用cmd()方法来实现 ...

  6. git设置代理

    git config --global https.proxy http://127.0.0.1:1080 git config --global https.proxy https://127.0. ...

  7. oracle中一个字符串包含另一个字符串中的所有字符

    oracle中一个字符串包含另一个字符串中的所有字符 --解决监理报告中所勾选的标段信息,与该用户所管理的标段字符串不匹配的问题. select * from a where instr(a,b)&g ...

  8. (C/C++) Callback Function 回调(diao)函数

    原文: http://www.codeguru.com/cpp/cpp/cpp_mfc/callbacks/article.php/c10557/Callback-Functions-Tutorial ...

  9. API爬虫--Twitter实战

    本篇将从实际例子出发,展示如何使用api爬取twitter的数据. 1. 创建APP 进入https://apps.twitter.com/,创建自己的app.只有有了app才可以访问twitter的 ...

  10. Java多线程之Wait()和Notify()

    1.Wait()和Notify.NotifyAll都是Object的方法 2.多线程的协作是通过控制同一个对象的Wait()和Notify()完成 3.当调用Wait()方法时,当前线程进入阻塞状态, ...