Title Link: http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085
Test instructions: The largest number of inverse primes in n (<=10^100).
Ideas:
Optimization 2:
int prime[]={1, 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,211,223,2 229,233,239,241,251};int k[]={1,2,2,3,3, 4,4,5,5,5, 5,5,6,6,6, 6,6,6,6,7, 7,7,7,7,7, 7,7,7,7,7, 7,7,8,8,8, 8,8,8,8,8, 8,8,8,8,8, 8,8,8,8,8, 8,8,8,8,8};struct bigint{int a[27]; BIGINT () {} BIGINT (char *s) {clr (a,0); int I,l=strlen (s), cur=0; for (i=l-1;i-3>=0;i-=4) {a[cur]= (s[i-3]-' 0 ') *1000+ (s[i-2]-' 0 ') *100+ (s[i-1]-' 0 ') *10+ (s[i]-' 0 '); cur++; } if (i<0) return; if (i==0) a[cur]=s[0]-' 0 '; else if (i==1) a[cur]=10* (s[0]-' 0 ') + (s[1]-' 0 '); else if (i==2) a[cur]=100* (s[0]-' 0 ') +10* (s[1]-' 0 ') + (s[2]-' 0 '); } BIGINT (int x) {clr (a,0); A[0]=x; } inline BIGINT operator* (int x) {int i; BIGINT tmp; for (i=0;i<27;i++) tmp.a[i]=a[i]*x; for (i=0;i<26;i++) {tmp.a[i+1]+=tmp.a[i]/10000; tmp.a[i]%=10000; } return TMP; } int operator< (BIGINT p) {int i; for (i=26;i>=0;i--) {if (A[i]<p.a[i]) return 1; if (A[i]>p.a[i]) return 0; } return 0; } int operator== (BIGINT p) {int i; for (i=26;i>=0;i--) {if (A[i]!=p.a[i]) return 0; } return 1; } int operator<= (BIGINT p) {return *this==p| | *this<p; } void print () {int cur=26; while (Cur>0&&0==a[cur]) cur--; printf ("%d", a[cur]); cur--; while (cur>=0) printf ("%04d", a[cur--]); Puts (""); }}; Char s[111]; BIGINT N;int Max; int cnt2; BIGINT ans;i64 ANSFAC; void DFS (int dep,bigint cur,i64 facnum,iNT Premax) {if (facnum>ansfac| | Facnum==ansfac&&cur<ans) {ans=cur; Ansfac=facnum; } int i; I64 Tmp=facnum; int min=min (PREMAX,2*K[MAX]-1-1); if (dep>1) min=min (min,cnt2/(k[dep]-1)); for (i=1;i<=min;i++) {if (dep==1) cnt2=i; CUR=CUR*PRIME[DEP]; Tmp+=facnum; if (n<cur) break; DFS (Dep+1,cur,tmp,i); }} int main () {scanf ("%s", s); N=bigint (s); if (N==bigint (1)) {puts ("1"); return 0; } BIGINT Cur=bigint (1); while (cur<=n) Cur=cur*prime[++max]; DFS (1,bigint (1), 1,100); Ans.print ();}
Bzoj 3085: Anti-prime version sapgap (inverse prime search)