• 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[1001] ;
    int  x , y ;
    void init(){
        for(int i=1;i<=1000;i++)
              N_3[i]=i*i*i  ;
       // cout<<N_3[1000]<<endl ;
    }
    int calc(){
        int a_up ,b_up ,c ,sum ,ans=0 ;
        a_up=Min(y,1000) ;
        b_up=Min(y,1000) ;
        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%10==3){
                       int c=sum/10 ;
                       if(x<=c&&c<=y)
                            ans++ ;
                  }
        }
        return ans ;
    }
    int main(){
        init() ;
        int k=1 ;
        while(scanf("%d%d",&x,&y)!=EOF){
            printf("Case %d: %d
    ",k++ ,calc()) ;
        }
        return 0 ;
    }
  • 相关阅读:
    url的非法字符有哪些
    asp.net各种获取客户端ip方法
    可编辑表格
    菜单弹出隐藏
    淡入淡出窗口
    使用XML传递数据
    Intellij IDEA将工程打包成jar包并执行
    使用JavaScript实现ajax
    AJAX基本演示使用
    统计指定目录下的视频时长
  • 原文地址:https://www.cnblogs.com/liyangtianmen/p/3370007.html
Copyright © 2020-2023  润新知