Advertisement
shamiul93

LightOJ 1220 - Mysterious bacteria

Mar 23rd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #define ll                                      long long
  4. #define fi                                      freopen("in.txt", "r", stdin)
  5. #define fo                                      freopen("out.txt", "w", stdout)
  6.  
  7. using namespace std;
  8.  
  9. long long int solve(long long int num)
  10. {
  11.     long long int ans=1,i,res;
  12.     int neg=0;
  13.     if(num<0)
  14.     {
  15.         neg=1;
  16.         num*=-1;
  17.     }
  18.     for(i=2; i*i<=num; i++)
  19.     {
  20.         if(num%i) continue;
  21.         long long int temp=num;
  22.         res=0;
  23.         while(temp%i==0)
  24.         {
  25.             temp/=i;
  26.             res++;
  27.         }
  28.         if(temp==1)
  29.         {
  30.  
  31.             if(!(neg && res%2 == 0)) /// if the x is negative then the power can never be even number .
  32.                 return res;
  33.         }
  34.     }
  35.     return 1;
  36. }
  37. int main()
  38. {
  39.  
  40.     //freopen("in.txt", "r", stdin);
  41.  
  42.     int cs,t;
  43.     scanf("%d",&t);
  44.     for(cs=1; cs<=t; cs++)
  45.     {
  46.         long long int num;
  47.         scanf("%lld",&num);
  48.  
  49.         printf("Case %d: %lld\n",cs,solve(num));
  50.     }
  51.     return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement