CF27E Number With The Given Amount Of Divisors

时间:2021-08-21
本文章向大家介绍CF27E Number With The Given Amount Of Divisors,主要包括CF27E Number With The Given Amount Of Divisors使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题目

CF27E Number With The Given Amount Of Divisors

分析

不知道为什么这种提这么多。

根据因数和公式,发现质因数个数很少,于是直接搜索即可。

代码

#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x){
    x=0;char ch=getchar();bool f=false;
    while(!isdigit(ch)){if(ch=='-'){f=true;}ch=getchar();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return ;
}
template <typename T>
inline void write(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10^48);
    return ;
}
const int N=1e5+5,M=1e6+5,MOD=1e9+7;
int n,p[100]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,47},a[20];
long long Ans=0x3f3f3f3f3f3f3f3f;
double QuickPow(double a,long long b){double res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
void dfs(int pos,int now){
	if(now==1){
		double res=1;
		for(int i=1;i<=pos-1;i++) res=res*QuickPow(p[i],a[i]-1);
		if(res<=1e18) Ans=min(Ans,(long long)res);
		return ;
	}
	for(int i=now;i>=2;i--) if(now%i==0) a[pos]=i,dfs(pos+1,now/i);
	return ;
}
int main(){
	read(n);
	dfs(1,n);
	write(Ans);
	return 0;
}

原文地址:https://www.cnblogs.com/Akmaey/p/15169216.html