The Super Powers
来源:互联网 发布:节奏大师没有网络可用 编辑:程序博客网 时间:2024/06/14 05:06
The Super Powers
以后还要记得再自己写恩!!!
/*#include<iostream>#include<cmath>#include<set> #include<climits>using namespace std;typedef long long ll;const ll maxn=1e10+1;//素数打表和STL集合 打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。set<long long>super;ll prime[maxn];void superpower(){ for(int i=2;i<=maxn;i++) if(!prime[i]) { for(ll j=i+i;i<maxn;j+=i) prime[j]=1; for(ll j=pow(i,4);j<0;j*=pow(i,2)) { super.insert(j); } }}int main(){ superpower(); for(set<long long>::iterator it=super.begin();it!=super.end();++it) cout<<*it<<endl; return 0;}i^j<=(2^64-1)可化为j<=ln(2^64-1)/lni。(为了防爆long long,可以用double)素数打表和STL集合 }*///i^j<=(2^64-1)可化为j<=ln(2^64-1)/lni。(为了防爆long long,可以用double)//素数打表和STL集合 打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace std;typedef unsigned long long LL;set<LL> table;bool h[100];int notPrime[100];int top;void calPrime()//存储非素数 (64以下的 ) 因为2^64就已经是最大的了,其他的n^64会更大{ for (int i = 2; i <= 64; i++) { if (!h[i]) for (int j = i + i; j <= 64; j += i) h[j] = true; else notPrime[top++] = i; }}//快速幂(取模)运算 LL powLL(LL a, int b){ LL res = 1; while (b) { if (b & 1)//判断是不是奇数 res *= a; a *= a; b >>= 1; } return res;}int main(){ calPrime(); LL maxNum = ~0ULL;//unsigned long long 类型的0 :而:~0就是这最大值 for (int i = 2;; i++) { LL n = maxNum; int t = 0; while (n >= i) n /= i, t++;// if (t<4) break;//当这个n/i的次数小于四次的时候也就说明,i很大了???要溢出啦???恩对。 for (int j = 0; j<top; j++)//top 为非素数的数量 if (notPrime[j] <= t)// table.insert(powLL(i, notPrime[j])); //素数打表和STL集合 打印所有super power数。不难发现,如果m不是素数,n^m一定是super power数。 } puts("1");//set集合里面是没有1的,输出1 for (set<LL>::iterator it = table.begin(); it != table.end(); it++) printf("%llu\n", *it);//llu:无符号长整型 return 0;}
这道题一开始我是不知道怎么写,然后就直接用上面的方法,感觉没有任何理由的。。。后来看别人怎么写的,,,恩这点很重要:m不是素数,n^m一定是super power数。 用了个素数打表,然后用快速幂取模,重点最后 判断 恩,什么时候截止
快速幂取模
int power(int a,int n,int m){ int res=1; while(n){ if(n&1) { res*=a; res%=m; } a*=a; a%=m; n>>1;} return res; }
阅读全文
0 0
- Uva11752 The Super Powers
- The Super Powers
- UVA11752 The Super Powers
- The Super Powers
- The Super Powers UVA
- UVA11752 The Super Powers
- 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
- UVA 11752 The Super Powers
- android 文字的处理
- 在分布式配置K3中间层时报中间层创建事务失败 处理方法
- 【DP】HDU 6170/2017多校9 1010 Two strings
- static的作用
- 学生信息管理系统之实时错误3021
- The Super Powers
- Qt编程公众号二维码
- 树状数组的三种模式
- poj 3026
- Xutils概述
- 放假两个月,我几乎没碰过代码,你也和我一样在面对迷茫吗?
- 算法模板之KM(带权的二分匹配)
- Error:Execution failed for task ':app:processDebugManifest'
- 寻C++程序员兼职创业