Submission
# | When | Author | Problem | Language | CPU | Memory | |
---|---|---|---|---|---|---|---|
20636 | 2024-05-23 14:43:46 | sumaiyaamin | Square Reconstruction | C++ 17 | 6 ms | 3388 kb | Accepted |
Source Code
#include <bits/stdc++.h> using namespace std; long long minimum_m(long long n) { long long m = 1; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { int count = 0; while (n % i == 0) { n /= i; count++; } if (count % 2 != 0) { // If the count of this prime factor is odd m *= i; // Multiply m by this prime to make the count even } } } if (n > 1) { // If there's any prime factor larger than sqrt(n) m *= n; // It will have an odd count (1), so multiply m by this prime } return m; } int main() { int t; cin >> t; while (t--) { long long n; cin >> n; cout << minimum_m(n) << endl; } return 0; }