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;}