Advertisement
Mohammad_Dipu_Sultan

UVA 11466 - Largest Prime Divisor

Feb 17th, 2021
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.20 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. // #include <iostream>
  3. // #include <cstdio>
  4. // #include <cstdlib>
  5. // #include <algorithm>
  6. // #include <cmath>
  7. // #include <vector>
  8. // #include <set>
  9. // #include <map>
  10. // #include <queue>
  11. // #include <ctime>
  12. // #include <cassert>
  13. // #include <complex>
  14. // #include <string>
  15. // #include <cstring>
  16. // #include <queue>
  17. // #include <bitset>
  18.  
  19. using namespace std;
  20. typedef long long           ll;
  21. typedef unsigned long long  ull;
  22.  
  23. #define ff                  first
  24. #define ss                  second
  25. #define pb                  push_back
  26. #define mp                  make_pair
  27. #define in                  insert
  28. #define vi                  vector< int >
  29. #define vll                 vector< ll >
  30.  
  31.  
  32. #define f0(b)               for(int i=0;i<(b);i++)
  33. #define f00(b)              for(int j=0;j<(b);j++)
  34. #define f1(b)               for(int i=1;i<=(b);i++)
  35. #define f11(b)              for(int j=1;j<=(b);j++)
  36. #define f2(a,b)             for(int i=(a);i<=(b);i++)
  37. #define f22(a,b)            for(int j=(a);j<=(b);j++)
  38. #define RFOR(i,x,y)         for(int i=x;i>=y;i--)
  39. #define unq(v)              sort(all(v)),(v).resize(unique(all(v))-v.begin())
  40. #define all(v)              v.begin(),v.end()
  41. #define rall(v)             v.rbegin(),v.rend()
  42. #define reversed(s)         reverse(s.begin(), s.end())
  43.  
  44. #define testcase            ll t; cin>>t; while (t--)
  45. #define vout(v)             for(int ind=0;ind<v.size();ind++){ cout<<v[ind]; if(ind<v.size()-1) cout<<' '; else cout<<endl;}
  46. #define arrout(arr,i,x,y)   for(int i=x;i<=y;i++){ cout<<arr[i]; if(i<y) cout<<' '; else cout<<endl;}
  47. #define READ()              freopen("input.txt", "r", stdin)
  48. #define WRITE()             freopen("output.txt", "w", stdout)
  49.  
  50. #define sci(n)              scanf("%d",&n)
  51. #define scii(x,y)           scanf("%d %d",&x,&y)
  52. #define scl(n)              scanf("%lld",&n)
  53. #define scll(x,y)           scanf("%lld %lld",&x,&y)
  54. #define gtl(x)              getline(cin, (x))
  55.  
  56. #define PI                  acos(-1)
  57. #define CLR(x, y)           memset(x, y, sizeof(x))
  58. #define Precision(a)        cout << fixed << setprecision(a)
  59. #define Flame()             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  60. #define MAXP                1000006
  61. #define MOD                 1e9+7//10000007
  62. #define EPS                 1e-7
  63.  
  64. template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
  65. template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1);  else return Sqr(Pow(B,P/2));}
  66. template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
  67. template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
  68. template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
  69. template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
  70. template <typename T> inline string ToBinary(T n) {string r ;while(n != 0) {r = ( n % 2 == 0 ? "0" : "1" ) + r ; n >>= 1;} return r ;}
  71. long long BinaryToDecimal(string s) {int len = s.size();long long n = 0, p = 1;for (int i = len - 1; i >= 0; i-- , p *= 2) n += p * (s[i] - '0');return n;}
  72.  
  73. int Strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
  74. string Intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}
  75.  
  76. #define bug printf("**!\n")
  77. #define DB(x) cout << #x << " = " << x << endl
  78. #define DDB(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
  79. #define DDDB(x, y, z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
  80.  
  81.  
  82. int main()
  83. {
  84.    // Flame();
  85.     ll n;
  86.     while(cin >> n && n)
  87.     {
  88.         vector<ll> v;
  89.         if(n<0)
  90.         {
  91.             n=n*(-1);
  92.         }
  93.         ll x=n;
  94.         for(ll i=2; i*i<=n; i++)
  95.         {
  96.             if(x%i==0)
  97.             {
  98.                 while(x%i==0)
  99.                 {
  100.                     x/=i;
  101.                 }
  102.                 v.pb(i);
  103.             }
  104.         }
  105.         if(x>1) v.pb(x);
  106.         ll sz=v.size();
  107.         if(sz<=1) cout << -1 << endl;
  108.         else cout << v[sz-1] << endl;
  109.     }
  110.     return 0;
  111. }
  112.  
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement