The Super Powers UVA11752 超级幂

版权声明:转载请声明出处!!!https://blog.csdn.net/anthony1314 https://blog.csdn.net/anthony1314/article/details/81978047

题意:输出打印1到 2^64 - 1所有超级幂

如果一个数可以表示成两个或以上的数的幂,就是超级幂;

思路:所有数的合数次幂,都是超级幂;

AC代码:

#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<functional>
using namespace std;

#define ll long long
#define ull unsigned long long

using namespace std;

int prm[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};//素数表 64以内
int vis[70];

int main() {
	ull lim = ~0LL >> 1;//最大64位的边界
	set<ull> s;
	memset(vis, 0, sizeof(vis));
	for(int i = 0; i < 18; i++) {
		vis[prm[i]] = 1;
	}
	for(int i = 2; ; i++) {
		int cnt = -1;
		ull x = lim;
		while(x) {
			x /= i;
			cnt++;
		}
		if(cnt < 4) {
			break;
		}
		ull b = i;
		for(int j = 2; j <= cnt; j++) {
			b *= i;
			if(!vis[j]) {
				s.insert(b);
			}
		}
	}
	s.insert(1);
	set<ull>::iterator it;
	for(it = s.begin(); it != s.end(); it++) {
//		cout<<*it<<endl;
		printf("%llu\n",*it);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/anthony1314/article/details/81978047