UVA - 11752 The Super Powers

We all know the Super Powers ofthis world and how they manage to get advantages in political warfare or evenin other sectors. But this is not a political platform and so we will talkabout a different kind of super powers – “The Super Power Numbers”. A positivenumber
is said to be super power when it is the power of at least two differentpositive integers. For example 64 is a super power as 64 = 82 and 64=  43.You have to write a program that lists all super powers within 1 and 264-1 (inclusive).

Input

This program has noinput.

Output

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

Sample Input                              

Partial Judge Output

No input for this problem

 


1

16

64

81

256

512

.

.

.


ProblemSetter: Shahriar Manzoor, Special Thanks: Sohel Hafiz

题意:如果一个数是超级幂的话,那么它至少是两个不同正整数的幂,从小到大输出所有

思路:如果这个数是超级幂的话,那么它的指数一定是合数,如果我们先枚举底数,大小为1~(1<<16),然后在2^64-1的范围内找数

#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cmath>
typedef unsigned long long ll;
using namespace std;
const int maxn = 100;

int vis[maxn];

int main() {
	memset(vis, 0, sizeof(vis));
	for (int i = 2; i < 100; i++)
		if (!vis[i]) {
			for (int j = i*i; j < 100; j += i)
				vis[j] = 1;
		}
	set<ll> ans;
	for (ll i = 2; i < (1<<16); i++) {
		int top = ceil(64*log10(2)/log10(i));
		ll tmp = 1;
		for (int j = 1; j < top; j++) {
			tmp *= i;
			if (vis[j])
				ans.insert(tmp);
		}
	}
	printf("1\n");
	set<ll>::iterator ite = ans.begin();
	while (ite != ans.end())
		cout << *ite++ << endl;
	return 0;
}

UVA - 11752 The Super Powers

时间: 2024-10-13 22:32:57

UVA - 11752 The Super Powers的相关文章

uva 11752 The Super Powers(暴力)

题目:https://cn.vjudge.net/problem/UVA-11752 题解:这里只讨论处理越界的问题. 因为题目最上界是 264-1. 我们又是求次幂的. 所以当我们就可以知道 i 的时候的界限 limit = 264-1 / i.如果刚好前一个次幂是 limit,那么再乘一个 i 刚好等于 264-1,按照题意是符合的. 那么如果当前的 次幂 a 是大于 limit 的话,a*i 就一定越界(可以自己想一想为什么),这个时候就可以break了. 这一题用set 保存,因为set

UVA 11752 超级幂

UVA 11752 超级幂 Z - The Super Powers Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11752 Description 题意:定义一个数为超级幂,当这个数能表示成至少两个不同数字的幂时.如16=2^4,16=4^2.输出1~2^64-1范围内的超级幂. 思路:显然一个数能称为超级幂,这个数肯定是一个数的合数幂,即a^

UVA 10622 - Perfect P-th Powers(数论)

UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取所有质因子个数的gcd就是答案,但是这题有个坑啊,就是输入的可以是负数,负数的情况比较特殊,p只能为奇数,这时候是要把答案不断除2除到为奇数即可. 代码: #include <stdio.h> #include <string.h> #include <math.h> long long n; int prime[333333], vi

The Super Powers

The Super Powers Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description A The Super Powers   We all know the Super Powers of this world and how they manage to get advantages in political

UVA 766 - Sum of powers(伯努利数)

766 - Sum of powers 题意:求    转化成 的各系数 思路:在wiki看了伯努利数的性质,  可以推成 . 然后B为伯努利数,有公式, 如此一来就可以去递推求出每项伯努利数了,然后在根据n去通分,求出每一项的答案,中间过程用到了分数的运算. 代码: #include <stdio.h> #include <string.h> long long gcd(long long a, long long b) { if (!b) return a; return gc

uva 766 - Sum of powers(数学+递推)

题目连接:uva 766 - Sum of powers 题目大意:将Sk(n)=∑i=1nik化简成Sk(n)=ak+1nk+1+aknk+?+a0M 解题思路: 已知幂k,并且有(n+1)k=C(kk)nk+C(k?1k)nk?1+?+C(0k)n0结论. 所以令 (n+1)k+1?nk+1=C(kk+1)nk+C(k?1k+1)nk?1+?+C(0k+1)n0 nk+1?(n?1)k+1=C(kk+1)(n?1)k+C(k?1k+1)(n?1)k?1+?+C(0k+1)(n?1)0 - 2

The Super Powers UVA - 11752

题目大意:将范围从1~pow(2,64)-1内的super power输出.super power的定义:一个数x至少存在两种x=pow(i,k),(k!=1). 题解: 注意数据范围2的64次方-1,而long long 的范围是2的63次方-1,所以要用unsigned long long. 一个数x至少存在两种幂形式,说明这个幂可以拆开,即这个幂不是质数. 最小非质数(1除外)是4,所以我们只需要枚举2的16次方-1就可以了. 指数只需要枚举1~64就可以了.如果指数非质数,就放到集合中.

The Super Powers UVA - 11752(合数幂)

题意: 求1~2^64-1之间所有的 至少是两个不同的正整数的幂的数  升序输出 一个数的合数次幂即为这样的数 找出1~2^64-1中所有数的合数次幂 用set存起来(既能防止重复 又能升序) 最后输出就好了 #include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include

UVA 10622 Perfect P-th Powers

https://vjudge.net/problem/UVA-10622 将n分解质因数,指数的gcd就是答案 如果n是负数,将答案除2至奇数 原理:(a*b)^p=a^p*b^p #include<cmath> #include<cstdio> #include<algorithm> #define N 65550 using namespace std; int gcd(int a,int b) { return !b ? a : gcd(b,a%b); } int