Https://icpcarchive.ecs.baylor.edu/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & category = 589 & problem = 4407 & mosmsg = Submission + received + with + ID + 1528513
Factors
The fundamental theorem of arithmetic states that every integer greater than 1 can be uniquely represented as a product of one or more primes. While unique, several arrangements of the prime factors
May be possible. For example:
10 = 2*5 20 = 2*2*5
= 5*2 = 2*5*2
= 5*2*2
Let F (k) be the number of di erent arrangements of the prime factors of K. So F (10) = 2 and
F (20) = 3.
Given a positive number N, there always exists at least one number k such that F (K) = n. We want
To know the smallest such K.
Input
The input consists of at most 1000 test cases, each on a separate line. Each test case is a positive
Integer n <2
63
.
Output
For each test case, display its number N and the smallest number k> 1 such that F (K) = n.
Numbers in the input are chosen such that K <2
63
.
Sample Input
1
2
3
105
Sample output
1 2
2 6
3 12
105 720
In fact, there is no judge because of uvalive's evaluation problem. The data I tested myself is the same as the result of the previous ac ....
However, I am forced to use judge as a judge because I cannot use another AC code pair. If it is illegal, the output should be set as INF, then, the maximum value I set is different from the INF value set by the AC code. I thought I was wrong and debug for several days. Today, I found that the slot ,,,, in fact, I may always be right. Well, of course, I will talk about it later when uvalive is ready.
The idea is to reverse the prime number, see the tutorial http://blog.csdn.net/u011026968/article/details/38784687
Then write, it is very easy, is with the http://blog.csdn.net/u011026968/article/details/38787473 very much, basically directly copy
My code:
# Include <cstdio> # include <cstring> # include <algorithm> # include <string> # include <iostream> # include <iomanip> # include <cmath> # include <map> # include <set> # include <queue> using namespace STD; # define ls (RT) rt * 2 # define RS (RT) rt * 2 + 1 # define ll long # define ull unsigned long # define rep (I, S, e) for (INT I = s; I <E; I ++) # define repe (I, S, e) for (INT I = s; I <= E; I ++) # define Cl (a, B) memset (a, B, sizeof (A) # defi NE in (s) freopen (S, "r", stdin) # define out (s) freopen (S, "W", stdout) const ll ll_inf = (ull) (-1)> 1; const double EPS = 1e-8; const int INF = 100000000; const int maxc = 100; // const int mod = 1e9 + 7; ll C [maxc] [maxc]; void calc () {// C (n, k), select K int I, J in N; for (INT I = 0; I <maxc; I ++) C [I] [I] = C [I] [0] = 1ll; For (INT I = 2; I <maxc; I ++) for (j = 1; j <I; j ++) c [I] [J] = (C [I-1] [J] + C [I-1] [J-1]); // % MOD;} const int size = 21; int P [Size] = {, 11, 17, 29, 47,}; // 7; 53; 59; 61; 67; 71; 73ll ans, N; void DFS (ll tmp, int DEP, int num, ll ret, int CC) {// printf ("tmp = % LLD Dep = % d num = % d ret = % LLD cc = % d \ n ", TMP, DEP, num, RET, CC ); /// // If (ret = N) ans = min (ANS, TMP ); if (Ret> = n | Dep> size-1) return; ll TT = 1; for (INT I = 1; I <num; I ++) {TT * = P [Dep]; // /// Printf ("n = % LLD Le = % LLD rI = % LLD \ n", N, N/ret, c [CC + I] [I], ANS/TT, TMP ); /// // If (N/RET> C [CC + I] [I] | ANS/TT <TMP) break; // If (ANS/TT <TMP) break; // If (CC + I> 64) break; DFS (TMP * TT, DEP + 1, I + 1, RET * C [CC + I] [I], CC + I) ;}} int main () {// In ("uva6396.txt"); calc (); While (~ Scanf ("% LLD", & N) {ans = ll_inf; If (n = 1) ans = 2; else DFS (1, 0, 65, 1, 0); printf ("% LLD \ n", N, ANS);} return 0 ;}
AC code:
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define FOR(i, x, y) for(int i = x; i <= y; i++)#define oo 0x3f3f3f3fusing namespace std;typedef long long ll;ll N;ll C[65][65];int P[20];bool isPrime(int n){FOR(i, 2, sqrt(n))if(n % i == 0) return 0;return 1;}void init(){FOR(i, 0, 64){C[i][0] = 1;FOR(j, 1, i)C[i][j] = C[i-1][j] + C[i-1][j-1];}FOR(i, 2, 64)if(isPrime(i))P[++P[0]] = i;}ll ans;int a[65];int sum[65];void dfs(int dep, ll s){if(s == 1){double temp = 0;FOR(i, 1, dep - 1)temp += a[i] * log(P[i]);ll t = 1;if(temp < 63 * log(2)){FOR(i, 1, dep - 1)FOR(j, 1, a[i])t *= P[i];ans = min(ans, t);}}if(s <= 1) return;FOR(i, 1, a[dep - 1]){a[dep] = i;sum[dep] = sum[dep-1] + i;if(sum[dep] > 64) break;if(C[sum[dep]][i] && s % C[sum[dep]][i] == 0)dfs(dep + 1, s / C[sum[dep]][i]);}}ll solve(){ans = 9223372036854775807L;a[0] = 64;dfs(1, N);if(N == 1) ans = 2;return ans;}int main(){init();while(scanf("%lld", &N) != EOF){printf("%lld %lld\n", N, solve());}return 0;}
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cstdlib>#include <utility>#include <map>using namespace std;#define IN(s) freopen(s,"r",stdin)#define maxn 1009int p[]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};typedef unsigned long long ull;ull mod = 1000000007;const ull INFULL=(ull)(-1LL);map<ull,ull> ans;ull n[maxn];bool safemul(ull &c,int x){if((c*x)%mod!=((c%mod)*x)%mod)return false;c*=x;return true;}ull qpow(ull a,ull n,ull mod){ull b=1;a%=mod;while(n){if(n&1) b*=a,b%=mod;a*=a,a%=mod;n>>=1;}return b;}void dfs(int t,int s,int sum,ull a,ull b,ull c){ull tmp = b*qpow(a,mod-2,mod)%mod;if(ans.find(tmp)!=ans.end()){ull &x = ans[tmp];if(x>c) x=c;}if(t>15)return;int i;for(i=1;i<=s;i++){b*=i+sum,b%=mod;a*=i,a%=mod;if(!safemul(c,p[t])) return;dfs(t+1,i,sum+i,a,b,c);}}int main(){//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);//IN("uva6396.txt");int p=0;while(cin>>n[++p]){ans[n[p]%mod]=INFULL;}p--;dfs(1,64,0,1,1,1);int i;for(i=1;i<=p;i++){if(n[i]==1){cout<<"1 2"<<endl;continue;}cout<<n[i]<<" "<<ans[n[i]%mod]<<endl;}return 0;}
Uvalive 6396 number theory world finals