HDU6623 思维题(n分解成质因子的形式,问最小的幂是多少)
题目大意:给你一个数n,把它分解为素数的幂次的乘积的形式:n=p1^e1 * p2^e2 * .......pk^ek 求最小的幂次是多少
n=le18
分析:
首先我们肯定是不可以枚举1e18的因子的,因为sqrt(1e18)=1e9 ,这样铁超时,那么1s的时间我们是可以预处理出10000以内的素数,我们首先得意思到n在10000以后的素数的幂都不可能大于5了,这很好理解(10001)^5>1e18 , 所以我们可以先用10000以内的素数算出一个最小幂 和剩余数Y, 在枚举看看后面可不可能出来4,3,2,1的幂; 这也很容易寻找,(Y^(1/4))^4==Y,就说明有4的幂 , 3,2,1同理,需要注意,在枚举3的幂的时候,sqrt()的精度会不行,所以需要二分逼近一下
注意一点:对于后面的情况只会出现 a^1*b^2 a^1*b^3 a^2 a^3 a^4 所以我们只要判断 a^2 a^3 a^4这种情况,其他都是1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll pr[];
bool vis[];
int tot;
void init(){
for(int i=;i<;i++){
if(vis[i]==){
pr[++tot]=i;
for(int j=i*;j<;j+=i)
vis[j]=;
}
}
}
bool fun(ll n){
ll l=,r=pow(n*1.0,1.0/3.0)+;
while(l<=r){
ll mid=(l+r)>>;
if(mid*mid*mid==n) return ;
else if(mid*mid*mid>n) r=mid-;
else l=mid+;
}
return ;
}
int main(){
init();
int _; scanf("%d",&_);
while(_--){
ll n;
scanf("%lld",&n);
int ans=0x3f3f3f3f; for(int i=;i<=tot;i++){
if(pr[i]>n) break; int x=;
while(n%pr[i]==){
n/=pr[i];
x++;
}
if(x!=)
ans=min(ans,x);
}
// cout<<n<<endl;
if(n==||ans==) printf("%d\n",ans);
else {
ll m1=(ll)sqrt(sqrt(n*1.0)*1.0);
ll m2=(ll)sqrt(n*1.0);
if(m1*m1*m1*m1==n) ans=min(ans,);
else if(fun(n)) ans=min(ans,);
else if(m2*m2==n) ans=min(ans,);
else ans=;
printf("%d\n",ans);
}
}
}
HDU6623 思维题(n分解成质因子的形式,问最小的幂是多少)的更多相关文章
- 【C/C++】任意大于1的整数分解成素数因子乘积的形式
// #include<stdio.h> #include<math.h> #include<malloc.h> int isprime(long n); void ...
- cf822D(质因子)
题目链接: http://codeforces.com/problemset/problem/822/D 题意: 输入 t, l, r 求 t0·f(l) + t1·f(l + 1) + ... + ...
- POJ2992:Divisors(求N!因子的个数,乘性函数,分解n!的质因子(算是找规律))
题目链接:http://poj.org/problem?id=2992 题目要求:Your task in this problem is to determine the number of div ...
- 整数(质因子)分解(Pollard rho大整数分解)
整数分解,又称质因子分解.在数学中,整数分解问题是指:给出一个正整数,将其写成几个素数的乘积的形式. (每个合数都可以写成几个质数相乘的形式,这几个质数就都叫做这个合数的质因数.) .试除法(适用于范 ...
- hdu6237 分解质因子
题意:给一堆石子,每次移动一颗到另一堆,要求最小次数使得,所有石子数gcd>1 题解:枚举所有质因子,然后找次数最小的那一个,统计次数时,我们可以事先记录下每堆石子余质因子 的和,对所有石子取余 ...
- Codeforces Round #828 (Div. 3) E2. Divisible Numbers (分解质因子,dfs判断x,y)
题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a ...
- UVA 10780 Again Prime? No Time. 分解质因子
The problem statement is very easy. Given a number n you have to determine the largest power of m,no ...
- HDU 4497 GCD and LCM(分解质因子+排列组合)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4497 题意:已知GCD(x, y, z) = G,LCM(x, y, z) = L.告诉你G.L,求满 ...
- HDU 4135 Co-prime (容斥+分解质因子)
<题目链接> 题目大意: 给定区间[A,B](1 <= A <= B <= 10 15)和N(1 <=N <= 10 9),求出该区间中与N互质的数的个数. ...
随机推荐
- 关于js计算非等宽字体宽度的方法
准备一个容器 首先在body外插入一个absolute的容器避免重绘: const svgWidthTestContainer = document.createElement('svg'); svg ...
- springboot导包spring-boot-starter-parent出现错误
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- intellij 编译 springmvc+hibernate+spring+maven 找不到hbm.xml映射文件
1. 错误信息 Invocation of init method failed; nested exception is org.hibernate.MappingNotFoundException ...
- 2019-11-29-dotnet-使用-System.CommandLine-写命令行程序
title author date CreateTime categories dotnet 使用 System.CommandLine 写命令行程序 lindexi 2019-11-29 08:33 ...
- python-装饰器1
python-装饰器1 定义本质就是函数,(装饰其他函数)就是为其他函数添加附加功能原则:1.不能修改被装饰的函数的源代码2.不能修改被装饰的函数的调用方式 def logger(): print(' ...
- windows2008R2下安装sqlserver2008R2时,点setup.exe应用程序无法打开错误代码0xc0150004
windows2008R2下安装sqlserver2008R2时,点setup.exe应用程序无法打开错误代码0xc0150004 问题截图: 网上查的答案都是需要安装.net framework 3 ...
- Linux日常之命令uniq
命令uniq 作用是过滤文件内容重复部分 需要注意的是,该命令只是对相邻的行进行比较,若两个相同的行不相邻,不会被过滤掉 选项 -c,在每行行首显示出该行出现的次数 -d,只显示出重复的行 -u,只显 ...
- [uboot] (第二章)uboot流程——uboot-spl编译流程(转)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/ooonebook/article/det ...
- ESP8266-模拟输出(PWM)
PWM(Pulse Width Modulation,脉宽调制),是在保持波的频率不变的同时改变脉宽的技术 首先,我们来理解一下占空比.一个脉冲周期由一个ON周期(VCCC)和一个OFF周期(GND) ...
- 跨平台信息获取小工具第三版本(增加了继承、多线程、异常处理模块、excel表格内容剔除空格)
# coding=utf-8 import threadingimport paramikoimport osimport timeimport xlrdimport xlwtimport openp ...