uva 11752 -The Super Powers (数论)

港控/mmm° 2022-08-09 12:55 241阅读 0赞

We all know the Super Powers of this world and how they manage to get advantages in political warfareor even in other sectors. But this is not a political platform and so we will talk about a different kindof super powers — “The Super Power Numbers”. A positive number is said to be super power when itis the power of at least two different positive integers. For example 64 is a super power as 64 = 82 and64 = 43. You have to write a program that lists all super powers within 1 and 264 ? 1 (inclusive)

Input
This program has no input.

Output

Print all the Super Power Numbers within 1 and 2^64 -1. Each line contains a single super power number and the numbers are printed in ascending order.

Sample Input

No input for this problem

Partial Judge Output

1

16
64

81
256

512
.
.
.

题目大意:超级幂(要求要打到1-2^64 -1的数,该数是两个或以上的正整数的幂次方),没有输入,只有输出打表!

思路:首先想到了素数的合数次方,最小的合数(也就是幂)是4,那么最大的底数(也就是要打的素数表的最大值是2^16,也就是1<<16,开到65536的数组足够),按照这种思路,却T了很多次,最后问学长,才知道打的时候没有判断,到最后打的太多反而T了,加判断的方法是判断指数要小于ceil(64.0/log(i)*log(2)),按说到此应该Ac了,可是又wa了一次,原来一开始推错了,应该打所有数的合数次方,最后去重即可,表示用vector打素数的合数次方打的好伤心,正解用set/map存,去重和排序一体。

code:

  1. # include<iostream>
  2. # include<cstdio>
  3. # include<cstring>
  4. # include<set>
  5. # include<cmath>
  6. # include<algorithm>
  7. using namespace std;
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. const int N=65546;
  11. set<ull>s;
  12. set<ull>::iterator it;
  13. bool vis[N];
  14. ull mi (int n,int m) //二分幂
  15. {
  16. if (m==0) return 1;
  17. if (m%2==0)
  18. return mi(n,m/2)*mi(n,m/2);
  19. else
  20. return n*mi(n,m/2)*mi(n,m/2);
  21. }
  22. void get_prim() //打素数表
  23. {
  24. int i,j;
  25. memset(vis,true,sizeof(vis));
  26. vis[0]=vis[1]=false;
  27. for(i=2;i<N;++i)
  28. {
  29. if(!vis[i]) continue;
  30. for(j=i+i;j<N;j+=i)
  31. vis[j]=false;
  32. }
  33. }
  34. int main()
  35. {
  36. int i,j;
  37. s.insert(1);
  38. get_prim();
  39. for(i=2;i<=65536-1;++i)
  40. {
  41. double t=ceil(64.0/log(i)*log(2))-1; //关键:加指数判断
  42. for(j=4;j<=t;++j)
  43. {
  44. if(vis[j]) continue;
  45. s.insert(mi(i,j));
  46. }
  47. }
  48. for(it=s.begin();it!=s.end();++it)
  49. printf("%llu\n",*it);
  50. return 0;
  51. }

发表评论

表情:
评论列表 (有 0 条评论,241人围观)

还没有评论,来说两句吧...

相关阅读

    相关 UVA11752 The Super Powers

    最近几天的状态着实不好,数电设计的答辩不能更逗,万幸是终于到家了,看到群里有各种群赛十分开心,希望能找回刷题的动力,调整下状态。 这道题是很久前做的,细节记不太清了。。。

    相关 uva 10515——Powers Et Al.

    题意:这个题目题中的图片已经给的够清楚了,就算不怎么读题,也能yy大概的意思,况且题目也很短,很容易都出来就是给定 a,b,然后求a^b的个位数! 思路:开始想到了同

    相关 uva 10622——Perfect P-th Powers

    题意:给定一个数n,求最大的一个数k使得n=x^k。 思路1:正规的做法是把这个素数分解,然后求指数的最大公约数就是所求(听说有人取了最小值也能过,数据水吧!),素数

    相关 UVA 12298 Super Poker II(FFT)

    题意: 每个花色恰好选择一张牌 能够构成点数和大小为N的方案数 用类似生成函数的想法,多项式的幂值表示大小,前面的系数表示的是方案数 因此想到了多项式乘法,用F