Prime & 反素数plus
题意:
求因数个数为n的最小正整数k. n<=10^9输出其唯一分解形式
SOL:
模拟题,一眼看过去有点惊讶...这不是我刚看过的反素数吗...
咦数据怎么这么大,恩搞个高精吧...
于是T了...
真是丝帛...因为这题不用输出答案而是输出质因子与指数,那么高精也没什么卵用...
想想我们在反素数的时候除了记录还要做一件什么事呢...比较答案与当前搜索的大小...但这里是在太大了,所以就要找一个更小的通用比较方法...
傻逼想到了高精,帅的人都用了log
log由于其良好的性质log(a*b)=log(a)+log(b).
于是balabalabalabala....
Code:
/*========================================================================== # Last modified: 2016-03-18 08:32 # Filename: t1.cpp # Description: ==========================================================================*/ #define me AcrossTheSky #include <cstdio> #include <ctime> #include <cmath> #include <string> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #include <deque> #define lowbit(x) (x)&(-x) #define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++) #define FORP(i,a,b) for(int i=(a);i<=(b);i++) #define FORM(i,a,b) for(int i=(a);i>=(b);i--) #define ls(a,b) (((a)+(b)) << 1) #define rs(a,b) (((a)+(b)) >> 1) #define getlc(a) ch[(a)][0] #define getrc(a) ch[(a)][1] #define pb push_back #define find(a,b) lower_bound((a).begin(), (a).end(), (b))-(a).begin() #define INF 10000000000 #define maxn 3000 #define maxm 100000 #define pi 3.1415926535898 #define _e 2.718281828459 using namespace std; typedef long long ll; typedef unsigned long long ull; template<class T> inline void read(T& num) { bool start=false,neg=false; char c; num=0; while((c=getchar())!=EOF) { if(c=='-') start=neg=true; else if(c>='0' && c<='9') { start=true; num=num*10+c-'0'; } else if(start) break; } if(neg) num=-num; } /*==================split line==================*/ const double inf=1e18; const double eps=0.00000001; #define mx 107 int p[52]={0,2,3,5,7,11, 13,17,19,23,29, 31,37,41,43,47, 53,59,61,67,71, 73,79,83,89,97, 101,103,107,109,113, 127,131,137,139,149, 151,157,163,167,173, 179,181,191,193,197, 199}; int n,b[mx],c[mx]; double ans; void dfs(int x,double t,int num,int m) { if (n%num) return; if (num>n) return; if (num==n&&ans>t) { for (int i=1;i<=x+1;i++) b[i]=c[i]; ans=t; return; } else if (num==n) return; if (ans-log(p[x])<t) return; int d=n/num; for (int i=1;i*i<=d;i++) { if (d%i==0) { if (i-1<=m&&i!=1) { c[x]=i-1; dfs(x+1,t+log(p[x])*(i-1),num*i,i-1); c[x]=0; } if (i*i!=d&&d/i-1<=m) { c[x]=d/i-1; dfs(x+1,t+log(p[x])*(d/i-1),num*(d/i),d/i-1); c[x]=0; } } } } int main() { read(n); ans=inf; dfs(1,0,1,n); if (n==1) printf("1^1"); else printf("%d^%d",p[1],b[1]); for (int i=2;i<=45;i++) { if (!b[i]) break; printf("*%d^%d",p[i],b[i]); } printf("\n"); return 0; }
Sometimes it s the very people who no one imagines anything of. who do the things that no one can imagine.