Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. //Author : Sukarna Paul
  2.  
  3. #include<bits/stdc++.h>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/trie_policy.hpp>
  6. #include<ext/pb_ds/detail/standard_policies.hpp>
  7. #define pi acos(-1)
  8. #define pb push_back
  9. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  10. #define ll int64_t
  11. #define MAX 300005
  12. #define INF 0x3f3f3f3f
  13. template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
  14. template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);} // M is prime}
  15.  
  16. using namespace std;
  17. using namespace __gnu_pbds;
  18.  
  19. typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
  20. typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
  21. typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
  22.  
  23.  
  24.  
  25. int main(){
  26. IOS
  27. //freopen("output.txt","w",stdout);
  28. int t;
  29. cin>>t;
  30.  
  31. for(int tt=0;tt<t;tt++){
  32. ll n;
  33. cin>>n;
  34. bool sn=true;
  35. if(n<0){
  36. sn=false;
  37. n= abs(n);
  38. }
  39. vector<ll>vec;
  40. ll sqrn=sqrt(n)+1;
  41. for(ll i=2;i<=sqrn;i++){
  42. ll p=0;
  43. while(n%i==0){
  44. p++;
  45. n/=i;
  46.  
  47. }
  48. if(p>0)vec.pb(p);
  49. }
  50. cout<<"Case "<<tt+1<<": ";
  51. if(vec.size()==0){
  52. cout<<1<<"\n";
  53. continue;
  54. }
  55. sort(vec.begin(),vec.end());
  56. bool bl=true;
  57. for(int i=0;i<vec.size();i++){
  58. if(vec[i]%vec[0]!=0)bl=false;
  59. }
  60. if(sn==false){
  61. if(bl==true && vec[0]%2LL==1){
  62. cout<<vec[0]<<"\n";
  63. }
  64. else{
  65. int cur = vec[0];
  66. while(cur%2==0){
  67. cur/=2;
  68.  
  69. }
  70. cout<<cur<<"\n";
  71. }
  72. }
  73. else if(bl==true){
  74. cout<<vec[0]<<"\n";
  75. }
  76. else{
  77. cout<<1<<"\n";
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement