Loading...
Submission
Id When Author Problem Language CPU Memory Verdict
16902 2024-04-22 19:52:20 punter Square Reconstruction C++ 17 4 ms 3480 kb Accepted
Test Cases
CPU Memory Verdict
1 2 ms 3436 kb Accepted
2 1 ms 3472 kb Accepted
3 3 ms 3356 kb Accepted
4 3 ms 3400 kb Accepted
5 3 ms 3416 kb Accepted
6 4 ms 3476 kb Accepted
7 3 ms 3416 kb Accepted
8 3 ms 3320 kb Accepted
9 2 ms 3480 kb Accepted
10 2 ms 3404 kb Accepted
Source Code
program.cpp
Download
  1. /**
  2. * Author : Arif Ahmad
  3. * Date :
  4. * Algo :
  5. * Difficulty:
  6. */
  7.  
  8. #include <bits/stdc++.h>
  9. using namespace std;
  10.  
  11. #define INF_MAX 2147483647
  12. #define INF_MIN -2147483648
  13. #define INF (1 << 30)
  14. #define EPS 1e-9
  15. #define PI acos(-1.0)
  16. #define N 11234
  17. #define MOD 10000000007
  18. #define sz(x) (int)(x).size()
  19. #define all(x) (x).begin(), (x).end()
  20. #define pb push_back
  21. #define mp make_pair
  22. #define ms(x, a) memset((x), (a), sizeof(x))
  23. #define F first
  24. #define S second
  25. #define rep(i,a,b) for(int i=(a); i<(b); ++i)
  26. #define repC(i,x) for(size_t i=0; i<x.size(); ++i)
  27. #define repIT(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
  28. #define nn '\n'
  29. #define trace(x) cerr << #x << " = " << x << '\n';
  30. #define trace2(x,y) cerr << #x << "=" << x << "\t" << #y << "=" << y << '\n';
  31.  
  32. typedef long long LL;
  33. typedef pair<int,int> pii;
  34. typedef vector<int> vi;
  35. typedef vector<string> vs;
  36. typedef vector<char> vc;
  37. typedef vector<bool> vb;
  38. typedef vector< pii > vii;
  39. typedef map<string,int> msi;
  40. typedef map<int,int> mii;
  41. typedef map<char,int> mci;
  42. typedef map<int,string> mis;
  43.  
  44. template<class T> T Abs(T x) {return x>0 ? x : -x;}
  45. template<class T> T Max(T a, T b) {return a>b ? a : b;}
  46. template<class T> T Min(T a, T b) {return a<b ? a : b;}
  47. template<class T> T gcd(T a, T b) {return (b ? gcd(b,a%b) : a);}
  48. bool isVowel(char ch){ch=tolower(ch);return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');}
  49.  
  50. //int dx[4] = {-1, 0, 0, 1};
  51. //int dy[4] = {0, -1, 1, 0};
  52. //int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  53. //int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  54.  
  55. bool num[N];
  56. int primes[10000]; // there are 9592 primes between 1 and 100000
  57. map<int, int> factors;
  58. int maxSize;
  59.  
  60. void sieve()
  61. {
  62. int i,j,k;
  63.  
  64. memset(num, true, sizeof(num));
  65. num[0] = num[1] = false;
  66. for(i=4; i<N; i+=2) num[i] = false;
  67.  
  68. for(i=3,j=sqrt(N)+1; i<j; i+=2)
  69. {
  70. if(num[i] == true)
  71. {
  72. k = i;
  73. while(k+i < N)
  74. {
  75. k += i;
  76. num[k] = false;
  77. }
  78. }
  79. }
  80.  
  81. }
  82.  
  83. void store()
  84. {
  85. int total = 0;
  86. for(int i=2; i<N; i++)
  87. if(num[i]) primes[total++] = i;
  88. }
  89.  
  90. void primeFactorize(int n)
  91. {
  92. int i, sqrtN = (int) sqrt(n);
  93.  
  94. for(i=0; primes[i]<=sqrtN; i++) if(n%primes[i] == 0)
  95. {
  96. while(n%primes[i] == 0)
  97. {
  98. n /= primes[i];
  99. factors[primes[i]]++;
  100. }
  101. }
  102.  
  103. if(n > 1) factors[n]++;
  104. }
  105.  
  106.  
  107.  
  108. int main()
  109. {
  110. ios_base :: sync_with_stdio(0);
  111. cin.tie(0);
  112.  
  113. // #ifndef ONLINE_JUDGE
  114. // freopen("in.txt", "r", stdin);
  115. // #endif
  116.  
  117. int i, j, k, n, m, tc;
  118.  
  119. sieve();
  120. store();
  121.  
  122. cin >> tc;
  123. while(tc--) {
  124. cin >> n;
  125.  
  126. factors.clear();
  127. primeFactorize(n);
  128.  
  129. int ans = 1;
  130. bool is_prime = true;
  131. for(auto [k,v]: factors) {
  132. if(v % 2 == 1) {
  133.  
  134. ans *= k;
  135. }
  136. }
  137.  
  138. // if(ans == 1 and n > 1 and is_prime) ans = n;
  139. cout << ans << nn;
  140. }
  141.  
  142. return 0;
  143. }
  144.  
  145. /*
  146.  
  147. */
  148.