Inverse prime
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5723 Accepted Submission (s): 3355
Problem description The inverse prime is satisfied for any I (0<i<x), there is g (i) <g (x), (g (x) is the number of factors of x), then x is an inverse prime. Now give you an integer interval [a, b], please find out the x of the interval to make g (x) the largest.
Input first line n, next n line test data
The input includes a, B, 1<=a<=b<=5000, which indicates the closed interval [a, b].
The output is an integer that is the maximum number of the interval factor. If there are more than one, the minimum number is output.
Sample Input32 31 1047 359
Sample Output26240 originally wanted to find an inverse prime topic practice practiced hand, the result met a water problem. I can play the table, but here I also put the anti-prime template.
#include <iostream>#include<stdio.h>using namespacestd;intcnt[5005];voidinit () { for(intI=1; i<= the; i++){ for(intj=1; j*j<=i;j++){ if(i%j==0){ if(j*j==i) cnt[i]++; Else{Cnt[i]+=2; } } } }}intMain () {init (); inttcase; scanf ("%d",&tcase); while(tcase--){ intb; scanf ("%d%d",&a,&b); intMAX =-1, res=A; for(inti=a;i<=b;i++){ if(cnt[i]>MAX) {MAX=Cnt[i]; Res=i; }} printf ("%d\n", RES); } return 0;}
The following is a template for the inverse primes within [1,n]. Reference to the Acreamer God: http://blog.csdn.net/ACdreamers/article/details/25049767
/** This template can be used to calculate the number of inverse primes between [1,b]*/#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>#include<stdlib.h>using namespacestd;typedef unsignedLong LongULL;ConstULL INF = ~0ULL;intp[ -] = {2,3,5,7, One, -, -, +, at, in, to,Panax Notoginseng, A, +, -, -};intAns,n;intBest ;voidDfsintDeptintLimit,ull tmp,intnum) { ///to the leaf node, back if(Dept >= -)return; ///Num records the number of factors, if it encounters a smaller, update if(Num >Best ) { Best=num; Ans=tmp; } ///when the number of factors is the same, the lowest value if(num = = Best && ans > tmp) ans =tmp; for(intI=1; i<=limit;i++) { if(N/p[dept] < TMP) Break; DFS (Dept+1, I,tmp *= p[dept],num* (i+1)); }}intMain () {inttcase; scanf ("%d",&tcase); while(tcase--) {scanf ("%d",&N); Ans=INF; Best=0; DFS (0, the,1,1);///maximum no more than INF< 2^63printf ("%d\n", ans); } return 0;}
Hdu 2521 Inverse Prime (table)