题目链接:https://vjudge.net/problem/UVA-11752

题意:

一个超级数是能够至少能表示为两个数的幂,求1~2^64-1内的超级数。

题解:

1.可知对于 n = a^b,如果b是合数,那么n同样可以表示为: n = (a^k)^c,其中k*c = b。所以只需要枚举底数,然后再枚举指数,如果指数为合数,那么它就是一个超级数。

2.由于2^64-1已经是 unsigned LL 的最大值了,为了避免溢出,指数应该从当前底数能达到的最大指数开始枚举。

3.由于一个超级数可能被多次访问到,所以用STL的 set 可以解决重复、离散化的问题,而且还能排序。

代码如下:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <cmath>
 7 #include <queue>
 8 #include <stack>
 9 #include <map>
10 #include <string>
11 #include <set>
12 #define ms(a,b) memset((a),(b),sizeof((a)))
13 using namespace std;
14 typedef long long LL;
15 const int INF = 2e9;
16 const LL LNF = 9e18;
17 const int mod = 1e9+7;
18 const int maxn = 1e5+100;
19
20 int vis[100];
21 void init()
22 {
23     int m = sqrt(64+0.5);
24     for(int i = 2; i<=m; i++) if(!vis[i]) {
25         for(int j = i*i; j<64; j += i)
26             vis[j] = 1;
27     }
28 }
29
30 typedef unsigned long long ull;
31 set<ull>s;  //用set完成了排序加去重的功能
32 int main()
33 {
34     init(); //标记在64以为的合数
35     for(ull i = 2;; i++)    //枚举底数
36     {
37         int t = ceil(64*log(2)/log(i)) - 1;
38         if(t<4) break;
39         ull x = 1;
40         for(int j = 1; j<=t; j++)
41         {
42             x *= i;
43             if(vis[j]) s.insert(x);
44         }
45     }
46
47     s.insert(1);
48     set<ull>::iterator it;
49     for(it = s.begin(); it!=s.end(); it++)
50         cout<<*it<<endl;
51 }

View Code

转载于:https://www.cnblogs.com/DOLFAMINGO/p/8391584.html

UVA11752 The Super Powers —— 数论、枚举技巧相关推荐

  1. UVA11752 The Super Powers【超级幂+暴力+数论】

    We all know the Super Powers of this world and how they manage to get advantages in political warfar ...

  2. 上课睡觉-数论+枚举

    题目描述: 有 N 堆石子,每堆的石子数量分别为 a1,a2,-,aN. 你可以对石子堆进行合并操作,将两个相邻的石子堆合并为一个石子堆,例如,如果 a=[1,2,3,4,5],合并第 2,3 堆石子 ...

  3. UVA 12716 GCD XOR(数论+枚举+打表)

     题意:给你一个N,让你求有多少组A,B,  满足1<= B <= A <= N, 且 gcd(A,B) = A XOR B. 思路:首先我们能够得出两个结论: A-B > ...

  4. [蓝桥杯2016初赛]四平方和-数论+枚举

    题目描述 四平方和定理,又称为拉格朗日定理:每个正整数都可以表示为至多4个正整数的平方和. 如果把0包括进去,就正好可以表示为4个数的平方和. 比如: 5 = 0^2 + 0^2 + 1^2 + 2^ ...

  5. [蓝桥杯2018初赛]第几个幸运数-数论+枚举

    代码如下: #include <iostream> #include <cmath> using namespace std; typedef long long LL; LL ...

  6. Competitive Programming 3题解

    题目一览: Competitive Programming 3: The New Lower Bound of Programming Contests(1) Competitive Programm ...

  7. 《算法入门经典大赛——培训指南》第二章考试

    UVa特别考试 UVa站点专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

  8. 数学入门题——《算法竞赛入门经典-训练指南》

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=94017#overview 代码链接:https://github.com/Yv ...

  9. WordPress加速缓存插件WP Super cache安装方法及使用技巧

    当Wordpress博客的访问量逐渐升高时,如何加快Wordpress运行效率,减少服务器压力,提高Wordpress的访问速度,就成为了日益紧迫的事情了.话说Wordpress臃肿低效率的毛病在网上 ...

  10. [kuangbin带你飞]专题十四 数论基础

    A - Bi-shoe and Phi-shoe --筛素数 题意 一个竹竿长度为p,它的score值就是比p长度小且与且与p互质的数字总数,比如9有1,2,4,5,7,8这六个数那它的score就是 ...

最新文章

  1. Druid 配置 wallfilter
  2. zabbix简单入门
  3. Haskell 函数式编程快速入门【草】
  4. DFT泄露问题和DFT的频率轴表示方法(第三章离散傅里叶变换(3.8,3.13.4)学习笔记)
  5. MongoDB文件操作(支持大于4M数据)
  6. Django简介以及安装
  7. 奇妙的安全旅行之MD算法
  8. AOSP6.0.1 launcher3入门篇—hotseat相关实现
  9. 十年测开如何理解自动化测试里的数据驱动、关键字驱动思路
  10. java拦截器_springMVC入门(八)------拦截器
  11. 详细解说STL string
  12. 关于java中求和的方法,用可变变量来解决这个问题
  13. 用Java写一个浪费cpu的程序_Java程序是如何浪费内存的
  14. 怎么用php跨域请求
  15. C语言文件的相对和绝对路径写法,文件路径写法
  16. excel文件运行报错(xx.xlsx)不是有效的win32应用程序
  17. deepin访问不了网页
  18. OpenHarmony,一路前行,为了奇迹
  19. 疫情期间想做兼职增加收入,那你应该看看这四个网赚项目
  20. php将json转化成数组,php如何把json转换成数组

热门文章

  1. 在 Intellij IDEA 中 调试 angular e2e test
  2. 窄带物联网技术有望终结碎片化现状
  3. Spring Annotation是怎么工作的?
  4. 彻底了解HASH算法及应用(一)
  5. LINUX系统下监控DELL服务器硬盘状态
  6. java读取文件(按字符或字节读取)
  7. cocos2dx 3.0 触摸机制
  8. C#学习笔记_14_接口命名空间
  9. Noip2013花匠
  10. 数据平面可编程与SDN关系理解,以及数据平面可编程的理解