zoukankan      html  css  js  c++  java
  • hdoj 4282 A very hard mathematic problem

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4282

    解题思路:二分

      1 ///////////////////////////////////////////////////////////////////////////
      2 //problem_id: hdoj 4282
      3 //user_id: SCNU20102200088
      4 ///////////////////////////////////////////////////////////////////////////
      5 
      6 #include <algorithm>
      7 #include <iostream>
      8 #include <iterator>
      9 #include <iomanip>
     10 #include <cstring>
     11 #include <cstdlib>
     12 #include <string>
     13 #include <vector>
     14 #include <cstdio>
     15 #include <cctype>
     16 #include <cmath>
     17 #include <queue>
     18 #include <stack>
     19 #include <list>
     20 #include <set>
     21 #include <map>
     22 using namespace std;
     23 
     24 ///////////////////////////////////////////////////////////////////////////
     25 #pragma comment(linker,"/STACK:1024000000,1024000000")
     26 
     27 #define lson l,m,rt<<1
     28 #define rson m+1,r,rt<<1|1
     29 ///////////////////////////////////////////////////////////////////////////
     30 
     31 ///////////////////////////////////////////////////////////////////////////
     32 const double EPS=1e-8;
     33 const double PI=acos(-1.0);
     34 
     35 const int x4[]={-1,0,1,0};
     36 const int y4[]={0,1,0,-1};
     37 const int x8[]={-1,-1,0,1,1,1,0,-1};
     38 const int y8[]={0,1,1,1,0,-1,-1,-1};
     39 ///////////////////////////////////////////////////////////////////////////
     40 
     41 ///////////////////////////////////////////////////////////////////////////
     42 typedef long long LL;
     43 
     44 typedef int T;
     45 T max(T a,T b){ return a>b? a:b; }
     46 T min(T a,T b){ return a<b? a:b; }
     47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
     48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
     49 ///////////////////////////////////////////////////////////////////////////
     50 
     51 ///////////////////////////////////////////////////////////////////////////
     52 //Add Code:
     53 LL power(LL a,LL n){
     54     LL ret=1;
     55     while(n){
     56         if(n&1) ret*=a;
     57         a*=a;
     58         n>>=1;
     59     }
     60     return ret;
     61 }
     62 
     63 LL cal(LL x,LL y,LL z){
     64     return power(x,z)+power(y,z)+x*y*z;
     65 }
     66 
     67 LL erfen(LL x,LL z,LL k){
     68     LL l=x+1,r=(LL)pow(k,1.0/z);
     69     while(r>=l){
     70         LL m=(l+r)/2,temp=cal(x,m,z);
     71         if(temp==k) return 1;
     72         if(temp>k) r=m-1;
     73         else l=m+1;
     74     }
     75     return 0;
     76 }
     77 ///////////////////////////////////////////////////////////////////////////
     78 
     79 int main(){
     80     ///////////////////////////////////////////////////////////////////////
     81     //Add Code:
     82     LL k;
     83     while(scanf("%I64d",&k)!=EOF){
     84         if(k==0) break;
     85         LL ans=0;
     86         for(LL z=2;z<32;z++){
     87             for(LL x=1;power(x,z)<k/2;x++) ans+=erfen(x,z,k);
     88         }
     89         printf("%I64d
    ",ans);
     90     }
     91     ///////////////////////////////////////////////////////////////////////
     92     return 0;
     93 }
     94 
     95 ///////////////////////////////////////////////////////////////////////////
     96 /*
     97 Testcase:
     98 Input:
     99 9
    100 53
    101 6
    102 0
    103 Output:
    104 1
    105 1
    106 0
    107 */
    108 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    互联网经济和实体经济
    哈佛图书馆馆训
    程序的初步认知
    Part 89 to 91 Talking about pass the parameters in thread
    Part 100 Func delegate in c#
    Part 99 Lambda expression in c#
    Part 16 Important concepts related to functions in sql server
    Part 14 Mathematical functions in sql server
    Part 13 Cast and Convert functions in SQL Server
    Part 2 Creating, altering and dropping a database
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3317737.html
Copyright © 2011-2022 走看看