Hdu 2521 Inverse Prime (table)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.