zoukankan      html  css  js  c++  java
  • Eddy's爱好 hdu2204

    Eddy's爱好

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 1266    Accepted Submission(s): 541


    Problem Description
    Ignatius 喜欢收集蝴蝶标本和邮票,但是Eddy的爱好很特别,他对数字比较感兴趣,他曾经一度沉迷于素数,而现在他对于一些新的特殊数比较有兴趣。
    这些特殊数是这样的:这些数都能表示成M^K,M和K是正整数且K>1。
    正当他再度沉迷的时候,他发现不知道什么时候才能知道这样的数字的数量,因此他又求助于你这位聪明的程序员,请你帮他用程序解决这个问题。
    为了简化,问题是这样的:给你一个正整数N,确定在1到N之间有多少个可以表示成M^K(K>1)的数。
     
    Input
    本题有多组测试数据,每组包含一个整数N,1<=N<=1000000000000000000(10^18).
     
    Output
    对于每组输入,请输出在在1到N之间形式如M^K的数的总数。
    每组输出占一行。
     
    Sample Input
    10 36 1000000000000000000
     
    Sample Output
    4 9 1001003332
     
     1 #include <iostream>
     2 #include <string.h>
     3 #include <stdio.h>
     4 #include <math.h>
     5 using namespace std;
     6 int a[]= {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};
     7 int b[]= {6,10,14,15,21,22,26,33,34,35,38,39,46,51,55,57,58};
     8 long long n,an;
     9 void dfs()
    10 {
    11     int i;
    12     for(i=0; i<17; i++)
    13     {
    14         long long h=pow(n,1.0/a[i]);
    15         if(pow(h+1,a[i])<=n)h++;
    16         if(h<2)break;
    17         an+=h-1;
    18     }
    19     for(i=0; i<17; i++)
    20     {
    21         long long h=pow(n,1.0/b[i]);
    22         if(pow(h+1,b[i])<=n)h++;
    23         if(h<2)break;
    24         an-=h-1;
    25     }
    26     if(n-pow(2.0,30)>=0) an++;
    27     if(n-pow(2.0,42)>=0) an++;
    28     if(n-pow(3.0,30)>=0) an++;
    29     an++;
    30 }
    31 int main()
    32 {
    33     while(cin>>n)
    34     {
    35         an=0;
    36         dfs();
    37         cout<<an<<endl;
    38     }
    39 }
    View Code
  • 相关阅读:
    【其他】UTF-8带签名与不带签名
    【Python】Python 过滤列表
    【EF】EF扩展库(批量操作)
    【python】用 sqlacodegen 将存在的数据库表 转化成model.py
    【python】使用枚举类
    【python】Python: Enum枚举的实现
    【python】python sqlalchemy core
    【python】python字符串前面加u,r,b的含义
    【EF】Entity Framework Core 2.0 特性介绍和使用指南
    Asp.Net 之 前台绑定常用总结
  • 原文地址:https://www.cnblogs.com/ERKE/p/3631436.html
Copyright © 2011-2022 走看看