Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad) 1445C. Division Solution
Problem Link: https://codeforces.com/problemset/problem/1445/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
 - ///******Bismillahir-Rahmanir-Rahim******///
 - /// Abul Hasnat Tonmoy
 - /// Department of CSE,23rd batch
 - /// Islamic University,Bangladesh
 - ///**********ALLAH IS ALMIGHTY************///
 - #include <bits/stdc++.h>
 - #define ll long long
 - using namespace std;
 - ll fun(ll a, ll v, ll b) {
 - if (v == 1) return 1;
 - while (a % b == 0) a /= v;
 - return a;
 - }
 - int main() {
 - int t;
 - cin >> t;
 - while (t--) {
 - ll p, q;
 - cin >> p >> q;
 - if (p % q != 0) {
 - cout << p << endl;
 - continue;
 - }
 - ll ans = 1;
 - for (ll i = 1; i * i <= q; i++) {
 - if (q % i == 0) {
 - ans = max(ans, fun(p, i, q));
 - ans = max(ans, fun(p, q / i, q));
 - }
 - }
 - cout << ans << endl;
 - }
 - }
 


No comments