• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Uva 省赛傻逼题 J

总是看不清傻逼错误,不要不服!

Problem J

 Time limit: 1.000 seconds 

 

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

 

 1 #include <map>
 2 #include <string>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <iostream>
 6 #include <algorithm>
 7 using namespace std;
 8 #define maxn 1111
 9 #define ll long long
10 int n,m;
11 int k[11];
12 int a[11][maxn];
13 int sq[11][maxn];
14 int main(){
15     for(int i=0;i<=1000;i++){
16         int t=i*i*i;
17         if(t%10==0){sq[0][k[0]]=i;a[0][k[0]++]=t;}
18         if(t%10==1){sq[1][k[1]]=i;a[1][k[1]++]=t;}
19         if(t%10==2){sq[2][k[2]]=i;a[2][k[2]++]=t;}
20         if(t%10==3){sq[3][k[3]]=i;a[3][k[3]++]=t;}
21         if(t%10==4){sq[4][k[4]]=i;a[4][k[4]++]=t;}
22         if(t%10==5){sq[5][k[5]]=i;a[5][k[5]++]=t;}
23         if(t%10==6){sq[6][k[6]]=i;a[6][k[6]++]=t;}
24         if(t%10==7){sq[7][k[7]]=i;a[7][k[7]++]=t;}
25         if(t%10==8){sq[8][k[8]]=i;a[8][k[8]++]=t;}
26         if(t%10==9){sq[9][k[9]]=i;a[9][k[9]++]=t;}
27     }
28     int cas=1;
29     while(scanf("%d%d",&n,&m)!=EOF){
30         int ans=0;
31         for(int i=0;i<=1005;i++)
32         for(int j=0;j<=1005;j++){
33             if(sq[0][i]>=n&&sq[0][i]<=m&&sq[3][j]>=n&&sq[3][j]<=m&&(a[0][i]+a[3][j])/10>=n&&(a[0][i]+a[3][j])/10<=m)ans++;
34             if(sq[1][i]>=n&&sq[1][i]<=m&&sq[2][j]>=n&&sq[2][j]<=m&&(a[1][i]+a[2][j])/10>=n&&(a[1][i]+a[2][j])/10<=m)ans++;
35             if(sq[4][i]>=n&&sq[4][i]<=m&&sq[9][j]>=n&&sq[9][j]<=m&&(a[4][i]+a[9][j])/10>=n&&(a[4][i]+a[9][j])/10<=m)ans++;
36             if(sq[5][i]>=n&&sq[5][i]<=m&&sq[8][j]>=n&&sq[8][j]<=m&&(a[5][i]+a[8][j])/10>=n&&(a[5][i]+a[8][j])/10<=m)ans++;
37             if(sq[6][i]>=n&&sq[6][i]<=m&&sq[7][j]>=n&&sq[7][j]<=m&&(a[6][i]+a[7][j])/10>=n&&(a[6][i]+a[7][j])/10<=m)ans++;
38         }
39         printf("Case %d: ",cas++);
40         printf("%d\n",ans*2);
41     }
42     return 0;
43 }
View Code 2013-10-14 14:15:11 

 

posted @ 2013-10-14 14:15  HaibaraAi  阅读(150)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3