UVA11752 The Super Powers
来源:互联网 发布:主域名服务器 编辑:程序博客网 时间:2024/05/24 05:55
题目链接:点我
题意:
输出所有的可以表示为至少两个不同数的次方的形式数.
思路:
先用素数筛选法找出64以内的合数,以为只有幂是合数才可以进行拆分。然后枚举底数进行判断,所有小于2^64-1的数都是满足的,这里有一个技巧,就是说2^64-1已经是unsign long long 的最大值了,那么超过它的数就会变成负数。但其实i的最大次幂是可以求的,x = logi(2^64-1) = log(2^64-1) / log(i);
代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<iostream>#include<set>using namespace std;int ex[100]={ 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 60, 62, 63, 64};typedef unsigned long long ull;int main(){ set<ull> q; q.insert(1); ull maxn=( 1 << 16) - 1; for(ull i = 2; i <= maxn; ++i){ ull tmp = i * i * i * i;//底数 q.insert(tmp); int k = ceil(64 * log(2)/log(i)) - 1;//指数的上限 for(int j = 1; ex[j] <= k; ++j){ if(ex[j] ==ex[j-1] + 1) tmp *= i; else tmp = tmp * i * i; q.insert(tmp); } } for(set<ull>::iterator it = q.begin();it != q.end();++it) cout<<*it<<endl; return 0;}
阅读全文
0 0
- Uva11752 The Super Powers
- UVA11752 The Super Powers
- UVA11752 The Super Powers
- UVA11752-The Super Powers(素数表+log)
- The Super Powers
- The Super Powers
- The Super Powers UVA
- The Super Powers
- The Super Powers
- The Super Powers UVA
- The Super Powers UVA
- UVA - 11752 The Super Powers
- UVA 11752-The Super Powers
- Uva 11752 The Super Powers
- UVA 11752 The Super Powers
- uva 11752The Super Powers
- UVA 11752 The Super Powers
- uva 11752 The Super Powers
- IO流的基本知识点
- linux中的磁盘分区
- SDUT-2498 图结构练习——判断给定图是否存在合法拓扑序列
- CentOS7 linux下DNS的永久性添加
- 关于HTTP协议,一篇就够了
- UVA11752 The Super Powers
- 红黑树——初步剖析
- Iterator遍历集合时不可以删除集合中的元素问题
- io操作之File类
- 创建Cocoapods Private 踩过的那些坑
- 企业级 Web 网站安全解决方案揭秘
- 典型静态方法的实现(algs4)
- UVA 133
- 实现半圆环状UI排版