UVA11752 The Super Powers —— 数论、枚举技巧
题目链接: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 可以解决重复、离散化的问题,而且还能排序。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e5+; int vis[];
void init()
{
int m = sqrt(+0.5);
for(int i = ; i<=m; i++) if(!vis[i]) {
for(int j = i*i; j<; j += i)
vis[j] = ;
}
} typedef unsigned long long ull;
set<ull>s; //用set完成了排序加去重的功能
int main()
{
init(); //标记在64以为的合数
for(ull i = ;; i++) //枚举底数
{
int t = ceil(*log()/log(i)) - ;
if(t<) break;
ull x = ;
for(int j = ; j<=t; j++)
{
x *= i;
if(vis[j]) s.insert(x);
}
} s.insert();
set<ull>::iterator it;
for(it = s.begin(); it!=s.end(); it++)
cout<<*it<<endl;
}
UVA11752 The Super Powers —— 数论、枚举技巧的更多相关文章
- uva 11752 The Super Powers (数论+枚举)
题意:找出1~2^64-1中 能写成至少两个数的幂形式的数,再按顺序输出 分析:只有幂是合数的数才是符合要求的.而幂不会超过64,预处理出64以内的合数. 因为最小的合数是4,所以枚举的上限是2的16 ...
- UVA11752 The Super Powers
/* UVA11752 The Super Powers https://vjudge.net/contest/153365#problem/Y 数论 注意a^n=b要用除法求,并且求得的n比实际大1 ...
- The Super Powers UVA 11752 分析分析 求无符号长整形以内的数满足至少可以用两种不同的次方来表示。比如64 = 2^6 = 8^2; 一个数的1次方不算数。
/** 题目:The Super Powers UVA 11752 链接:https://vjudge.net/contest/154246#problem/Y 题意:求无符号长整形以内的数满足至少可 ...
- The Super Powers
The Super Powers Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Subm ...
- 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 ...
- The Super Powers UVA - 11752
题目大意:将范围从1~pow(2,64)-1内的super power输出.super power的定义:一个数x至少存在两种x=pow(i,k),(k!=1). 题解: 注意数据范围2的64次方-1 ...
- 神奇的Noip模拟试题第一试 合理种植 枚举+技巧
1.合理种植 (plant.pas/.c/.cpp) [问题描述] 大COS在氯铯石料场干了半年,受尽了劳苦,终于决定辞职.他来到表弟小cos的寒树中学,找到方克顺校长,希望寻个活干. 于是他如愿以偿 ...
- UVa 11752 (素数筛选 快速幂) The Super Powers
首先有个关键性的结论就是一个数的合数幂就是超级幂. 最小的合数是4,所以枚举底数的上限是pow(2^64, 1/4) = 2^16 = 65536 对于底数base,指数的上限就是ceil(64*lo ...
随机推荐
- [原创][FPGA]有限状态机FSM学习笔记(一)
1. 概述--何为有限状态机FSM? 有限状态机-Finite State Machine,简写为FSM,是表示有限个状态及在这些状态之间的转移和动作等行为的数学模型,在计算机领域有着广泛的应用.通常 ...
- luogu P1018 乘积最大
题目描述 今年是国际数学联盟确定的"2000――世界数学年",又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力竞赛的活动,你的一 ...
- Css实现一个菜单导航
提要:使用大div定位设置为relative,子div设置为absolute实现菜单下拉 实现代码: <!DOCTYPE html> <html lang="en" ...
- bubble chat listview
最近在iOS中用到bubble chat listview,找了个比较有名气的lib(MessagesTableViewController)=>https://github.com/jesse ...
- iOS 改变Search Bar中Scope Button中文本的颜色和字体
- (void)initSearchbar{ self.wineSearchBar.delegate = self; [self.wineSearchBar setScopeBarButtonTitl ...
- LINQ体验(13)——LINQ to SQL语句之运算符转换和ADO.NET与LINQ to SQL
运算符转换 1.AsEnumerable:将类型转换为泛型 IEnumerable 使用 AsEnumerable<TSource> 可返回类型化为泛型 IEnumerable 的參数.在 ...
- RobotFramework --RIDE介绍
RIDE是robotframework的图形操作前端,我们在RIDE上进行测试用例设计和编写测试脚本,并执行自动化测试.下面来全面的认识下这个操作工具. 在右边编辑页面有三大模块,Edit,TextE ...
- SGPIO
http://en.wikipedia.org/wiki/SGPIO SGPIO From Wikipedia, the free encyclopedia Serial General Purp ...
- Django-mysq数据库链接问题
Django链接MySQL数据库有可能会报no model named MySQLdb, 解决办法: 首先安装pymysql 然后进入到项目目录,找到__init__.py文件,在里面添加 impor ...
- ipython notebook 如何打开.ipynb文件?
标签: pythontensorflow 2017-03-29 14:17 235人阅读 评论(0) 收藏 举报 分类: TensorFlow(13) 转自:https://www.zhihu.c ...