Advertisement
erfanul007

UVa 11466

Apr 28th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. #define read() freopen("input.txt", "r", stdin)
  7. #define write() freopen("output.txt", "w", stdout)
  8.  
  9. void mxdiv(ll n)
  10. {
  11. ll x = n, mx = -1, cnt =0;
  12. if(n%2==0){
  13. cnt++;
  14. while(n%2==0){
  15. n/=2;
  16. }
  17. }
  18. for(ll i=3;i*i<=n;i+=2){
  19. if(n%i==0){
  20. cnt++;
  21. mx = max(mx,i);
  22. while(n%i==0){
  23. n/=i;
  24. }
  25. }
  26. }
  27. if(n>1 && n!=x){
  28. cnt++;
  29. mx = max(mx,n);
  30. }
  31. if(cnt<=1) mx = -1;
  32. printf("%lld\n",mx);
  33. }
  34.  
  35. int main()
  36. {
  37. //read();
  38. //write();
  39.  
  40. ios_base::sync_with_stdio(false);
  41. cin.tie(NULL);
  42.  
  43. ll n;
  44. while(1){
  45. scanf("%lld",&n);
  46. if(n==0) break;
  47. if(n<0) n*=-1;
  48. mxdiv(n);
  49. }
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement