Advertisement
Falak_Ahmed_Shakib

Big_Prime

Aug 7th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // In the name of Allah.
  2. // We're nothing and you're everything.
  3. // Ya Ali!
  4. /*
  5. , \ / ,
  6. / \ )\__/( / \
  7. / \ (_\ /_) / \
  8. ____/_____\__\@ @/___/_____\____
  9. | |\../| |
  10. | \VV/ |
  11. | ------___------- |
  12. |__________Chuta Dragon___________|
  13. | /\ / \\ \ /\ |
  14. | / V )) V \ |
  15. |/ ` // ' \|
  16. ` V '
  17. */
  18.  
  19. #include<bits/stdc++.h>
  20. using namespace std;
  21. typedef long long ll;
  22. typedef pair<ll,ll>pll;
  23. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  24. #define fi first
  25. #define se second
  26. #define pb push_back
  27. ///-------------------------------------------------------------------------------------------------///
  28. /// KARMA IS LIKE 69,,, YOU GET WHAT YOU GIVE ///
  29. ///-------------------------------------------------------------------------------------------------///
  30. void input(ll ara[],ll n)
  31. {
  32. for(ll i=0; i<n; i++)
  33. cin>>ara[i];
  34. }
  35.  
  36. void output(ll ara[],ll n)
  37. {
  38. for(ll i=0; i<n; i++)
  39. cout<<ara[i]<<" ";
  40. }
  41.  
  42. #define eb emplace_back
  43.  
  44. const int N=1e7;
  45. ll k;
  46. //bitset<N+10>ara;
  47.  
  48. ll ara[N+10];
  49.  
  50. vector<ll>v;
  51.  
  52. void sieve()
  53. {
  54. ara[0]=1;
  55. ara[1]=1;
  56.  
  57. v.pb(2);
  58.  
  59. int i,j,sz=sqrt(N);
  60.  
  61. for(i=2; i<=sz; i++)
  62. {
  63. if(ara[i]==0)
  64. {
  65. v.push_back(i);
  66.  
  67. for(j=i*2; j<=N; j+=i)
  68. {
  69. ara[j]=1;
  70.  
  71. }
  72. }
  73. }
  74.  
  75.  
  76. for(ll i=sz+1; i<=N; i++)
  77. {
  78. if(ara[i]==0)
  79. {
  80. v.pb(i);
  81. }
  82. }
  83.  
  84. k=v.size();
  85.  
  86. }
  87. ll prime(ll t)
  88. {
  89. if(t<=N)
  90. {
  91. if(ara[t]==0)return 1;//prime
  92. else return 0;// a[0]=1 mana not prime
  93. }
  94. else
  95. {
  96. ll m=sqrt(t);
  97. //condi:1(i<k) mana vcetor or full ar modda na takla prime must;
  98. //condi:1(v[i]<=m) mana vector ar any value jodi sqrt(t) ar boro hala prime must (it is a prime low)
  99. for(ll i=0;i<k && v[i]<=m;i++)
  100. {
  101. if(t%v[i]==0)return 0;
  102. }
  103. return 1;
  104.  
  105. }
  106.  
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113. int main()
  114. {
  115.  
  116. sieve();// suru ta e sieve must (void funtion must call)
  117. ll n;
  118.  
  119. while(cin>>n && n)
  120. {
  121.  
  122. n=abs(n);
  123.  
  124.  
  125. ll mx=-1,cnt=0;
  126. ll len=sqrt(n);
  127.  
  128. for(ll i=2;i<=len;i++)
  129. {
  130. if(n%i==0)
  131. {
  132. if(prime(i))
  133. {
  134. cnt++;
  135. mx=max(i,mx);
  136. }
  137.  
  138. if(prime(n/i) && n/i!=i)//n/i!=9 must coz 9=3,3
  139. {
  140. cnt++;
  141. mx=max(n/i,mx);
  142. }
  143. }
  144. }
  145.  
  146. if(cnt<2)cout<<-1<<endl;
  147. else cout<<mx<<endl;
  148.  
  149.  
  150.  
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement