题目链接: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 —— 数论、枚举技巧的更多相关文章

  1. uva 11752 The Super Powers (数论+枚举)

    题意:找出1~2^64-1中 能写成至少两个数的幂形式的数,再按顺序输出 分析:只有幂是合数的数才是符合要求的.而幂不会超过64,预处理出64以内的合数. 因为最小的合数是4,所以枚举的上限是2的16 ...

  2. UVA11752 The Super Powers

    /* UVA11752 The Super Powers https://vjudge.net/contest/153365#problem/Y 数论 注意a^n=b要用除法求,并且求得的n比实际大1 ...

  3. The Super Powers UVA 11752 分析分析 求无符号长整形以内的数满足至少可以用两种不同的次方来表示。比如64 = 2^6 = 8^2; 一个数的1次方不算数。

    /** 题目:The Super Powers UVA 11752 链接:https://vjudge.net/contest/154246#problem/Y 题意:求无符号长整形以内的数满足至少可 ...

  4. The Super Powers

    The Super Powers Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Subm ...

  5. uva 11752 The Super Powers 素数+大数判断大小

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  6. UVA 11752 The Super Powers —— 数学与幂

    题目链接:https://vjudge.net/problem/UVA-11752 题解: 1.首先变量必须用unsig long long定义. 2.可以分析得到,当指数为合数的时候,该值合法. 3 ...

  7. The Super Powers UVA - 11752

    题目大意:将范围从1~pow(2,64)-1内的super power输出.super power的定义:一个数x至少存在两种x=pow(i,k),(k!=1). 题解: 注意数据范围2的64次方-1 ...

  8. 神奇的Noip模拟试题第一试 合理种植 枚举+技巧

    1.合理种植 (plant.pas/.c/.cpp) [问题描述] 大COS在氯铯石料场干了半年,受尽了劳苦,终于决定辞职.他来到表弟小cos的寒树中学,找到方克顺校长,希望寻个活干. 于是他如愿以偿 ...

  9. UVa 11752 (素数筛选 快速幂) The Super Powers

    首先有个关键性的结论就是一个数的合数幂就是超级幂. 最小的合数是4,所以枚举底数的上限是pow(2^64, 1/4) = 2^16 = 65536 对于底数base,指数的上限就是ceil(64*lo ...

随机推荐

  1. 1005 Spell It Right

    1005 Spell It Right   Given a non-negative integer N, your task is to compute the sum of all the dig ...

  2. 554 DT:SPM 163 smtp5,D9GowAD3RPYqSvxZjpMaAA--.4817S2 1509706293 坑爹的防垃圾邮件机制

    代码如下 package ssmtest; import java.io.File;import java.io.UnsupportedEncodingException;import java.ut ...

  3. Akka简介与Actor模型

    Akka是一个构建在JVM上,基于Actor模型的的并发框架,为构建伸缩性强,有弹性的响应式并发应用提高更好的平台.本文主要是个人对Akka的学习和应用中的一些理解. Actor模型 Akka的核心就 ...

  4. 什么叫PV,UV,PR值

    1.PV PV(page view),即页面浏览量:用户每1次对网站中的每个网页访问均被记录1次.用户对同一页面的多次访问,访问量累计. 2.什么是UV uv(unique visitor),指访问某 ...

  5. arcgis andriod Edit features

    来自:https://developers.arcgis.com/android/guide/edit-features.htm#ESRI_SECTION1_56C60DB71AF941E98668A ...

  6. tar命令中的-C作用

    一直不知道解压命令如何指定文件夹,今天学到了一个 -C 参数 tar zxvf test.tar.gz -C test 注释:上面的命令将 test.tar.gz 这个压缩包解压到当前目录下的 tes ...

  7. sqlalchemy如何实现时间列自动更新?

    目标:数据表的时间列在其他列内容更新的时候,自动更新时间列到更新的时间 方法:数据库表模型如下:server_default表示初始时间,onupdate表示更新的时间 class MonitorDa ...

  8. 132-pattern(蛮难的)

    https://leetcode.com/problems/132-pattern/ 下面是我的做法.后来又看了一个提示: https://discuss.leetcode.com/topic/678 ...

  9. OpenCV for Python 学习笔记 一

    本人的学习笔记主要记录的是学习opencv-python-tutorials这本书中的笔记 今天晚上简单学习OpenCV for Python如何绘图,主要用了这几个函数(这几个函数可在:http:/ ...

  10. 服务管理-tomcat

    Tomcat是Apache软件基金会的Jakarta项目中的一个核心项目,由Apache,Sun和其他一些公司及个人共同开发而成.由于有了Sun的参与和支持,最新的Servlet和JSP规范总是能在T ...