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. map<int,int>factors;
  32.  
  33. void factoriz(int n){
  34. factors.clear();
  35. for(int i = 2; i*i <= n ; i++){
  36. while(n%i == 0){
  37. factors[i]++;
  38. n /= i;
  39. }
  40. }
  41.  
  42. if(n != 1){
  43. factors[n]++;
  44. }
  45. }
  46. /**************************************************************/
  47. int main(){
  48.  
  49. //freopen("in.txt" , "rt",stdin) ;
  50. //freopen("out.txt", "wt", stdout);
  51. int n ;
  52. while(cin >> n){
  53.  
  54. if(n == -1){
  55. break;
  56. }
  57.  
  58.  
  59. factoriz(abs(n));
  60. bool isFree = true;
  61.  
  62. for(map<int,int>::iterator it = factors.begin();
  63. it != factors.end(); it++){
  64. // cout << it->first << ' ' << it->second << '\n';
  65.  
  66. if(it->second > 1){
  67. isFree = false;
  68. break;
  69. }
  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 2868KB
stdin
-18
-1
stdout
-18 is not square-free