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. 1 10
  2. 1 20
  3. 123 456789

Output for the Sample Input

  1. Case 1: 0
  2. Case 2: 2
  3. 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)。

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <queue>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <vector>
  7. #include <queue>
  8. #include <set>
  9. #include <algorithm>
  10. #include <map>
  11. #include <stack>
  12. #include <math.h>
  13. #define Max(a,b) ((a)>(b)?(a):(b))
  14. #define Min(a,b) ((a)<(b)?(a):(b))
  15. using namespace std ;
  16. typedef long long LL ;
  17. LL N_3[] ;
  18. int x , y ;
  19. void init(){
  20. for(int i=;i<=;i++)
  21. N_3[i]=i*i*i ;
  22. // cout<<N_3[1000]<<endl ;
  23. }
  24. int calc(){
  25. int a_up ,b_up ,c ,sum ,ans= ;
  26. a_up=Min(y,) ;
  27. b_up=Min(y,) ;
  28. for(int a=x;a<=a_up;a++)
  29. for(int b=x;b<=b_up;b++){
  30. sum=N_3[a]+N_3[b] ;
  31. if(sum%==){
  32. int c=sum/ ;
  33. if(x<=c&&c<=y)
  34. ans++ ;
  35. }
  36. }
  37. return ans ;
  38. }
  39. int main(){
  40. init() ;
  41. int k= ;
  42. while(scanf("%d%d",&x,&y)!=EOF){
  43. printf("Case %d: %d\n",k++ ,calc()) ;
  44. }
  45. return ;
  46. }

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. Android Wear(手表)开发 - 学习指南

    版权声明:欢迎自由转载-非商用-非衍生-保持署名.作者:Benhero,博客地址:http://www.cnblogs.com/benhero/ Android Wear开发 - 学习指南 http: ...

  2. WCF学习心得------(六)数据协定

    --前言 最近各种事忙的把之前的WCF学习给耽误了一些,今天抽时间把之前的学习内容给总结了一下,因为知识点比较细碎没有做太多的练习示例,只是对其中关键的知识点做了总结,希望可以对大家有所帮助. 第六章 ...

  3. Angular学习(1)

    天天都是hello world,老子玩1+1. 最简单的例子,见证无聊的时刻: <!DOCTYPE html> <html> <head> <title> ...

  4. 【Andorid开发框架学习】之Mina开发之客户端开发

    昨天我们讲到了Mina的基本知识点.如果还有不懂得同学可以看一下我昨天的博客.http://www.cnblogs.com/getherBlog/p/3934927.html今天我着重来讲一下基于Mi ...

  5. IntelliJ IDEA常用快捷键

    双击shift 项目所有目录查找 ctrl+f 文件查找特定内容 ctrl+shift+f 项目查找包含特定内容的文件 ctrl+n 新建类 ctrl+shift+n 查找文件 ctrl+e  最近的 ...

  6. FTP主/被动模式的原理

    ---------------------------------------------------------------------------------------------------- ...

  7. cgic 写CGI程序

    CGIC是C语言CGI库函数,用于编写CGI程序 CGIC 主要完成以下功能: * 对数据进行语法分析 * 接收以 GET 和 PSOT 两种方式发送的数据 * 把 FORM 中的不同域连接成连续的串 ...

  8. Python处理Excel文档(xlrd, xlwt, xlutils)

    简介 xlrd,xlwt和xlutils是用Python处理Excel文档(*.xls)的高效率工具.其中,xlrd只能读取xls,xlwt只能新建xls(不可以修改),xlutils能将xlrd.B ...

  9. 在Huawei USG2100 上配置通过Huawei VPN客户端的接入

    USG2100 设置 一.本地策略 中允许 Untrust 对 L2TP 的访问: 二.勾选 VPN-->L2TP 启用: 三.设置参数: 1.组类型选择LNS,本端隧道名称LNS,对端隧道名称 ...

  10. [转][色彩 A] – 永远不要使用纯黑

    原文地址:http://www.cgjoy.com/forum.php?mod=viewthread&tid=110762&extra=page%3D1%26filter%3Dtype ...