UVA 11752 The Super Powers【超级幂】
题目链接:
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=111527#problem/Z
题意:
我们称一个可以由至少两个不同正整数的幂的形式表示的数为超级幂。让你找出1到264−1之间的所有超级幂。
分析:
首先ax∗y=axy,也就是说超级幂必须存在一个为合数的指数。
底数最小为2,此时指数最大为64。
指数最小为4,此时底数最小为216。
暴力枚举一发即可。
因为ull的最大值为264−1,所以乘的过程中注意判断是否大于边界。
代码:
#include <iostream>
#include<set>
#include<cstdio>
using namespace std;
const int mod = 1e9 + 7, maxn = 64 + 5;
bool isprime[maxn];
#define ull unsigned long long
ull INF = (1<<64) - 1;
set<ull>s;
void getprime()
{
int n = 64;
fill(isprime, isprime + n, 1);
for(int i = 2; i * i <= n; i++){
if(isprime[i]){
for(int j = 2 * i; j <= n; j += i){
isprime[j] = false;
}
}
}
}
int main (void)
{
getprime();
for(int i = 2; i <= 65536; i++){
ull ans = 1;
for(int j = 1; j <= 64; j++){
ans *= i;
if(!isprime[j]) s.insert(ans);
if(ans > INF / i) break;
}
}
s.insert(1);
set<ull>::iterator a;
for(a = s.begin(); a != s.end(); a++)
cout<<*a<<endl;
return 0;
}
UVA 11752 The Super Powers【超级幂】的更多相关文章
- uva 11752 The Super Powers 素数+大数判断大小
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVA 11752 The Super Powers —— 数学与幂
题目链接:https://vjudge.net/problem/UVA-11752 题解: 1.首先变量必须用unsig long long定义. 2.可以分析得到,当指数为合数的时候,该值合法. 3 ...
- uva 11752 - The Super Powers
这个题 任意一个数,他的幂只要不是质数则可以分解成两个数的乘 判断有没有溺出 i×i 则用最大的那个数 Max/i < i 吗 #include<iostream> #i ...
- uva 11752 The Super Powers (数论+枚举)
题意:找出1~2^64-1中 能写成至少两个数的幂形式的数,再按顺序输出 分析:只有幂是合数的数才是符合要求的.而幂不会超过64,预处理出64以内的合数. 因为最小的合数是4,所以枚举的上限是2的16 ...
- UVA 11752 The Super Powers(暴力)
题目:https://cn.vjudge.net/problem/UVA-11752 题解:这里只讨论处理越界的问题. 因为题目最上界是 264-1. 我们又是求次幂的. 所以当我们就可以知道 i 的 ...
- UVa 11752 - The Super Powers 数学
请看这个说明http://blog.csdn.net/u014800748/article/details/45914353 #define _CRT_SECURE_NO_WARNINGS #incl ...
- UVa 11752 (素数筛选 快速幂) The Super Powers
首先有个关键性的结论就是一个数的合数幂就是超级幂. 最小的合数是4,所以枚举底数的上限是pow(2^64, 1/4) = 2^16 = 65536 对于底数base,指数的上限就是ceil(64*lo ...
- The Super Powers UVA 11752 分析分析 求无符号长整形以内的数满足至少可以用两种不同的次方来表示。比如64 = 2^6 = 8^2; 一个数的1次方不算数。
/** 题目:The Super Powers UVA 11752 链接:https://vjudge.net/contest/154246#problem/Y 题意:求无符号长整形以内的数满足至少可 ...
- BZOJ1709: [Usaco2007 Oct]Super Paintball超级弹珠
1709: [Usaco2007 Oct]Super Paintball超级弹珠 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 324 Solved: ...
随机推荐
- Ubuntu16下查看CPU、内存和磁盘相关信息
1.内存 查看内存#free -m total used free shared buff/cache available Mem: Swap: 2.CPU 查看逻辑cpu个数: #cat /proc ...
- ubuntu下nginx+PHP-FPM安装配置
安装nginx apt-get install nginx 配置nginx 位置: /etc/nginx/nginx.conf ,其中包含了 include /etc/nginx/conf.d/*. ...
- Javaweb学习笔记9—过滤器
今天来讲javaweb的第9阶段学习. 过滤器,我在本次的思维导图中将过滤器和监听器放在一起总结了,监听器比较简单就不单独写了. 老规矩,首先先用一张思维导图来展现今天的博客内容. ...
- JS正则匹配待重命名文件名
<script>var str = "123 - Copy(2).csv";var regExp = /^123( - Copy(\(\d+\))?)?.csv$/;d ...
- 在Servlet中使用@Autowire的方法
在你调用的Servlet中添加如下代码: public void init(ServletConfig config) { try { super.init(config); SpringBeanAu ...
- [Windows Server 2012] 安装IIS8.5及FTP
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:安装IIS ...
- 【算法】最长回文子串 longest palindrome substring
对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...
- integer to roman leetcode c++实现
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- Vue项目结构梳理
Vue项目结构图: 简单介绍目录结构 build目录是一些webpack的文件,配置参数什么的,一般不用动 config是vue项目的基本配置文件 node_modules是项目中安装的依赖模块 sr ...
- libcmt.lb libcmtd.lib与MSVCRTD.lib的冲突解决
system("pause"); 这个函数存在于MSVCRTD.lib库中: 当要使用system("pause")这个函数,且libcmt.lb libcmt ...