HDU 5108 Alexander and Prime Numbers (large Prime number)

Source: Internet
Author: User
Tags cmath

HDU 5108 Alexander and Prime Numbers (large Prime number)

Problem descriptionalexander Ra has a little brother. He is new to programming. One day he is solving the following problem: Given an positive integer N, judge whether N is prime.
The problem above is quite easy, so Alexander gave him a new task: Given a positive integer N, find the minimal positive integer M, such that N/M is prime. if such M doesn' t exist, output 0.
Help him!
InputThere are multiple test cases (no more than 1,000). Each case contains only one positive integer N.
N ≤ 1,000,000,000 .
Number of cases N> 1,000,000 Is no more than 100.
OutputFor each case, output the requested M, Z records? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> trim" brush: java; "> 3456
Sample Output
1212


For this question, I just want to say that I am stupid. for a large number of n, find the smallest m. Yes, n/m is the prime number.


First, n = Prime Number * prime number ......


So we can find the maximum prime number, and there cannot be two numbers greater than sqrt (n) in this prime number. The Code is as follows:


#include
 
  #include
  
   #include
   
    #include#include
    
     #include
     
      #define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)using namespace std;typedef __int64 ll;#define N 100000ll a[N],b[N];ll k;void inset(){int i,j;a[0]=1;for(i=2;i
      
       1;m--)if(n%m==0) { while(n%m==0&&!a[m])n/=m; if(!a[m]) { ans=max(ans,m); } }ans=(ll)max(ans,n);printf("%I64d\n",temp/ans);}return 0;}
      
     
    
   
  
 




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.