fork download
  1. /**
  2.  * @Author : sabry_ragab
  3.  * This is the right time to know him: http://w...content-available-to-author-only...h.net
  4.  */
  5.  
  6. #include<bits/stdc++.h>
  7.  
  8. using namespace std ;
  9.  
  10. typedef long long ll;
  11. typedef vector<int> vi;
  12. typedef pair<int,int> pii;
  13.  
  14. const double eps = 1e-10;
  15. const int dx[] = {1, 0, -1, 0};
  16. const int dy[] = {0, 1, 0, -1};
  17. const double pi = acos(-1.0);
  18. const int OO = (1<<30) ;
  19.  
  20. #define SZ(x) (int)x.size()
  21. #define ALL(x) (x).begin(),(x).end()
  22. #define ALLR(x) (x).rbegin(),(x).rend()
  23. #define PB( x ) push_back(x)
  24. #define MP(x , y) make_pair(x,y)
  25. #define rep(i,st,en) for(int i=st ; i< en; i++)
  26. #define repR(i,st,en) for(int i=st;i>=en ; i--)
  27. #define clr(v, d) memset(v, d, sizeof(v))
  28. #define printfloat(n) cout << fixed << showpoint << setprecision(n)//to be placed in the first line of the main
  29. template<class A, class B> A convert(B x) {stringstream s; s << x; A r; s >> r; return r;}
  30. /**************************************************************/
  31. bool isPerfectSquare(int n){
  32. int i = sqrt(n);
  33. return i*i == n;
  34. }
  35. /**************************************************************/
  36. int main(){
  37.  
  38. //freopen("in.txt" , "rt",stdin) ;
  39. //freopen("out.txt", "wt", stdout);
  40.  
  41. int n ;
  42. while(cin >> n){
  43.  
  44. if(n == -1){
  45. break;
  46. }
  47.  
  48. int number = abs(n); //i think it is not import as he said range [2,2^21]
  49. bool isFree = true;
  50.  
  51. for(int i = 2; i*i <= number; i++){//o(sqrt(n))
  52.  
  53. if(number % i == 0){
  54.  
  55. if(isPerfectSquare(i)){
  56. isFree = false;
  57. break;
  58. }
  59.  
  60. if(isPerfectSquare(n/i)){
  61. isFree = false;
  62. break;
  63. }
  64. }
  65.  
  66. }
  67.  
  68. if(isPerfectSquare(number)){
  69. isFree = false;
  70. }
  71.  
  72. if(isFree){
  73. cout << n << " is square-free\n";
  74. }else{
  75. cout << n << " is not square-free\n";
  76. }
  77.  
  78. }
  79. //--------------------------------------------------------//
  80. return 0;
  81. }
  82.  
Success #stdin #stdout 0s 2732KB
stdin
991
2097151
-1
stdout
991 is square-free
2097151 is not square-free