HDU 2136 (Prime number filter + integer decomposition)

Source: Internet
Author: User

Largest prime factor

Time limit:5000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 9993 Accepted Submission (s): 3528


Problem Descriptioneverybody knows any number can is combined by the prime number.
Now, your task was telling me what position of the largest prime factor.
The position of Prime 2 is 1, Prime 3 are 2, and Prime 5 is 3, etc.
Specially, LPF (1) = 0.

Inputeach line would contain one integer n (0 < n < 1000000).

Outputoutput the LPF (n).

Sample Input12345

Sample Output01213
#include <stdio.h>#include<math.h>#include<iostream>#include<algorithm>#include<string.h>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intN =1000000;BOOLP[n];///to False represents a prime numberintIdx[n];voidinit () {memset (P,false,sizeof(p)); intID =1;  for(intI=2; i<n;i++){        if(!P[i]) {Idx[i]= id++;  for(ll j= (LL) i*i;j<n;j+=i) {P[j]=true; }        }    }}intGetmax (intN) {    intMax =-1;  for(intI=2; i*i<=n;i++){        if(n%i==0){             while(n%i==0) {n/=i; } Max=Max (I,max); }    }    if(n>1) Max =Max (max,n); returnMax;}intMain () {init (); intN;  while(SCANF ("%d", &n)! =EOF) {        if(n==1) printf ("0\n"); Else{            intMax =Getmax (n); printf ("%d\n", Idx[max]); }    }}

HDU 2136 (Prime number filter + integer decomposition)

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.