51NOD 1060 最复杂的数 【反素数】
来源:互联网 发布:免费音乐广告制作软件 编辑:程序博客网 时间:2024/05/21 19:36
1060 最复杂的数题目来源: Ural 1748基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注把一个数的约数个数定义为该数的复杂程度,给出一个n,求1-n中复杂程度最高的那个数。例如:12的约数为:1 2 3 4 6 12,共6个数,所以12的复杂程度是6。如果有多个数复杂度相等,输出最小的。Input第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 100)第2 - T + 1行:T个数,表示需要计算的n。(1 <= n <= 10^18)Output共T行,每行2个数用空格分开,第1个数是答案,第2个数是约数的数量。Input示例5110100100010000Output示例1 16 460 12840 327560 64相关问题最复杂的数 V2 320李陶冶 (题目提供者)
反素数百科
反素数定义:对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数·性质:性质一:一个反素数的质因子必然是从2开始连续的质数.性质二:p=2^t1*3^t2*5^t3*7^t4.....必然t1>=t2>=t3>=....性质比较明显 就不作证明了 本题就是求<=n的最大的反素数 注意防溢出
#include<iostream>#include<stdlib.h>#include<stdio.h>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<time.h>#include<math.h>#include<list>#include<cstring>#include<fstream>#include<queue>#include<sstream>//#include<memory.h>using namespace std;#define ll long long#define ull unsigned long long#define pii pair<int,int>#define INF 1000000007#define pll pair<ll,ll>#define pid pair<int,double>const int N = 1e5;vector<int>primer;bool isPrimer[N];void initPrimer(){ fill(isPrimer,isPrimer+N,true); for(ll i = 2;i < N; ++i){ if(isPrimer[i]){ for(ll j = i*i; j < N; j += i){ isPrimer[j] = false; } } } for(int i = 2; i < N; ++i){ if(isPrimer[i]){ primer.push_back(i); } }}ll n;ll ans,maxYs;void dfs(int cur,ll prod,int ys,int maxt){//cur:第cur个素数,prod:素因子乘积,ys:约数个数,maxt:不能超过maxt个primer[cur]因子 if(ys>maxYs){ ans = prod; maxYs = ys; } else{ if(ys==maxYs){ ans = min(ans,prod); } } ll x = primer[cur]; //此处不能直接判断i*prod<=n 溢出 for(ll i=x,t=1;((n/i)/prod>=1)&&t<=maxt;i*=x,t+=1){ dfs(cur+1,i*prod,ys*(t+1),t); }}int main(){ //freopen("/home/lu/Documents/r.txt","r",stdin); //freopen("/home/lu/Documents/w.txt","w",stdout); initPrimer(); int T; scanf("%d",&T); while(T--){ scanf("%lld",&n); ans = n+1,maxYs=-1; dfs(0,1,1,INF); printf("%lld %lld\n",ans,maxYs); } return 0;}
0 0
- 51nod 1060:最复杂的数 反素数
- 51nod 1060 最复杂的数(反素数)
- 51nod 1060 最复杂的数(反素数)
- 51nod-1060 最复杂的数(反素数)
- 51NOD 1060 最复杂的数 【反素数】
- 51nod 1060 最复杂的数 反素数
- 51nod 1060 最复杂的数(反素数)
- 51nod 1060 最复杂的数(反素数)
- 51nod 1060 最复杂的数(数论:反素数)
- 51nod 最复杂的数(反素数)
- 51NOD 最复杂的数 暴力(反素数)
- 51nod-1060:最复杂的数(反素数与因数个数计算)
- 51Nod-1060-最复杂的数(反素数)
- 1060 最复杂的数(反素数)
- 反素数 51Nod1060 最复杂的数
- 51Nod 1060 最复杂的数
- 51NOD 1060 最复杂的数
- 51nod 1060 最复杂的数
- Centos7安装RocketMQ及配置测试
- Centos7安装JStorm2.1.1
- 运行到指定EIP处, 打内存补丁
- VB.net应用技巧5: VB.net 除法运算
- tf.gather_nd(params, indices, name=None)
- 51NOD 1060 最复杂的数 【反素数】
- Leetcode 151. Reverse Words in a String
- 196UVa电子表格
- <Python初学>Python中的变量类型。对赋值、浅拷贝与深拷贝的初步认识。
- Leetcode 98. Validate Binary Search Tree
- Leetcode 100. Same Tree
- COVER王锐大大——最长的一帧(第四日)
- Leetcode 101. Symmetric Tree
- Python轻松入门-09 Range函数和While循环