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; ; ...
随机推荐
- Android Wear(手表)开发 - 学习指南
版权声明:欢迎自由转载-非商用-非衍生-保持署名.作者:Benhero,博客地址:http://www.cnblogs.com/benhero/ Android Wear开发 - 学习指南 http: ...
- WCF学习心得------(六)数据协定
--前言 最近各种事忙的把之前的WCF学习给耽误了一些,今天抽时间把之前的学习内容给总结了一下,因为知识点比较细碎没有做太多的练习示例,只是对其中关键的知识点做了总结,希望可以对大家有所帮助. 第六章 ...
- Angular学习(1)
天天都是hello world,老子玩1+1. 最简单的例子,见证无聊的时刻: <!DOCTYPE html> <html> <head> <title> ...
- 【Andorid开发框架学习】之Mina开发之客户端开发
昨天我们讲到了Mina的基本知识点.如果还有不懂得同学可以看一下我昨天的博客.http://www.cnblogs.com/getherBlog/p/3934927.html今天我着重来讲一下基于Mi ...
- IntelliJ IDEA常用快捷键
双击shift 项目所有目录查找 ctrl+f 文件查找特定内容 ctrl+shift+f 项目查找包含特定内容的文件 ctrl+n 新建类 ctrl+shift+n 查找文件 ctrl+e 最近的 ...
- FTP主/被动模式的原理
---------------------------------------------------------------------------------------------------- ...
- cgic 写CGI程序
CGIC是C语言CGI库函数,用于编写CGI程序 CGIC 主要完成以下功能: * 对数据进行语法分析 * 接收以 GET 和 PSOT 两种方式发送的数据 * 把 FORM 中的不同域连接成连续的串 ...
- Python处理Excel文档(xlrd, xlwt, xlutils)
简介 xlrd,xlwt和xlutils是用Python处理Excel文档(*.xls)的高效率工具.其中,xlrd只能读取xls,xlwt只能新建xls(不可以修改),xlutils能将xlrd.B ...
- 在Huawei USG2100 上配置通过Huawei VPN客户端的接入
USG2100 设置 一.本地策略 中允许 Untrust 对 L2TP 的访问: 二.勾选 VPN-->L2TP 启用: 三.设置参数: 1.组类型选择LNS,本端隧道名称LNS,对端隧道名称 ...
- [转][色彩 A] – 永远不要使用纯黑
原文地址:http://www.cgjoy.com/forum.php?mod=viewthread&tid=110762&extra=page%3D1%26filter%3Dtype ...