solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int t, a, b;
vector<pair<int, int>> pa, pb;
vector<int> pr;
bool vis[N];
bool val() {
if (a * a != b && b * b != a) return false;
if (pa.size() != pb.size()) return false;
for (int i = 0; i < pa.size(); i++) {
if (pa[i].first != pb[i].first) return false;
if ((pa[i].second + pb[i].second) % 3) return false;
if (2 * min(pa[i].second, pb[i].second) < max(pa[i].second, pb[i].second))
return false;
}
return true;
}
int main() {
for (int i = 2; i <= 1e3; i++) {
if (vis[i]) continue;
pr.push_back(i);
for (int j = i; j <= 1e3; j += i) vis[j] = true;
}
scanf("%d", &t);
while (t--) {
scanf("%d %d", &a, &b);
pa.clear();
pb.clear();
for (int i : pr) {
if (a % i) continue;
pa.push_back({i, 0});
while (a % i == 0) {
pa.back().second++;
a /= i;
}
}
for (int i : pr) {
if (b % i) continue;
pb.push_back({i, 0});
while (b % i == 0) {
pb.back().second++;
b /= i;
}
}
if (val())
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int x, y;
int prime[100005];
bool is_prime[100005];
int t;
int sieve(int n) {
int p = 0;
for (int i = 0; i <= n; i++) is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i]) {
prime[p++] = i;
for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
}
}
return p;
}
long long _sqr(long long x) {
long long l = 1, r = 1000001;
while (r - l > 1) {
long long mid = (l + r) / 2;
if (mid * mid * mid <= x)
l = mid;
else
r = mid;
}
return l;
}
int main() {
int n;
scanf("%d", &n);
int num = sieve(32005);
for (int i = 0; i < n; i++) {
scanf("%d %d", &x, &y);
long long s = (long long)x * y;
long long res = _sqr(s);
if (res * res * res != s || x % res != 0 || y % res != 0) {
puts("No");
continue;
}
long long xx = x / res, yy = y / res;
if (xx * yy == res)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int T;
long long a, b, x;
int main() {
for (cin >> T; T--;) {
scanf("%lld%lld", &a, &b), x = pow(a * b, 1. / 3);
if ((x + 1) * (x + 1) * (x + 1) == a * b) x++;
puts(x * x * x != a * b || a % x || b % x ? "No" : "Yes");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long dx[] = {1, -1, 0, 0};
long long dy[] = {0, 0, 1, -1};
void solve() {
long long a, b;
cin >> a >> b;
long long num = a * b;
long long x = round(cbrt(num));
if (x * x * x != num)
cout << "No";
else {
if (a % x == 0 && b % x == 0)
cout << "Yes";
else
cout << "No";
}
return;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long q = 1;
cin >> q;
for (long long i = 0; i < q; i++) {
solve();
cout << "\n";
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T, typename X>
using pr = pair<T, X>;
const long long int MOD = 1e9 + 7;
const long double PI = 3.14159265;
long long int powerWithMod(long long int base, long long int exponent,
long long int modulus = LLONG_MAX) {
long long int result = 1;
base %= modulus;
while (exponent > 0) {
if (exponent % 2 == 1) result = (result * base) % modulus;
exponent >>= 1;
base = (base * base) % modulus;
}
return result;
}
long long int modInverse(long long int a, long long int m = MOD) {
return powerWithMod(a, m - 2, m);
}
int n;
long long int a, b;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
while (n--) {
cin >> a >> b;
auto c = a * b;
auto y = static_cast<long long int>(std::pow(c, 1 / 3.0));
while (y * y * y < c) y++;
if (y * y * y != c or a % y or b % y)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
| 7 | CPP |
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
avl=AvlTree()
#-----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default='z', func=lambda a, b: min(a ,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left)/ 2)
# Check if middle element is
# less than or equal to key
if (arr[mid]<=key):
count = mid+1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def countGreater( arr,n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
for i in range(int(input())):
a,b=map(int,input().split())
c=a*b
l=int(c**(1/3)+0.5)
if l**3==a*b and a%l==0 and b%l==0:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
import sys
input = sys.stdin.buffer.readline
def gcd(a, b):
if a > b:
a, b = b, a
if b % a==0:
return a
return gcd(b % a, a)
def process(a, b):
g = gcd(a, b)
r = a//g
s = b//g
if g % r != 0:
return 'No'
g = g//r
if g % s != 0:
return 'No'
G3 = g//s
G = round(G3**(1/3))
cube = False
for i in range(10):
if (G-i)**3==G3 or (G+i)**3==G3:
cube = True
break
if not cube:
return 'No'
return 'Yes'
n = int(input())
for i in range(n):
a, b = [int(x) for x in input().split()]
sys.stdout.write(process(a, b)+'\n') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int inline max3(int a, int b, int c) { return max(a, max(b, c)); }
int n;
long long ab, a, b;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%lld", &a);
scanf("%lld", &b);
ab = a * 1LL * b;
int l = 1, r = 1e6, mid;
while (l < r) {
mid = l + (r - l + 1) / 2;
if (1LL * mid * mid * mid <= ab)
l = mid;
else
r = mid - 1;
}
if (1LL * r * r * r == ab && a % r == 0 && b % r == 0)
puts("YES");
else
puts("NO");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
namespace chtholly {
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) f ^= c == '-';
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
return f ? x : -x;
}
template <typename mitsuha>
inline bool read(mitsuha &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c) && ~c; c = getchar()) f ^= c == '-';
if (!~c) return 0;
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
return x = f ? x : -x, 1;
}
template <typename mitsuha>
inline int write(mitsuha x) {
if (!x) return 0 & putchar(48);
if (x < 0) x = -x, putchar('-');
int bit[20], i, p = 0;
for (; x; x /= 10) bit[++p] = x % 10;
for (i = p; i; --i) putchar(bit[i] + 48);
return 0;
}
inline char fuhao() {
char c = getchar();
for (; isspace(c); c = getchar())
;
return c;
}
} // namespace chtholly
using namespace chtholly;
using namespace std;
long long T, a, b, t;
inline long long gcd(long long u, long long v) {
for (; u && v && u != v;) {
swap(u, v);
u %= v;
}
return max(u, v);
}
int main() {
long long i, j, l, r, mid, t, ji, g, ji2;
cin >> T;
while (T--) {
scanf("%lld%lld", &a, &b);
ji = ji2 = a * b;
a = b = gcd(a, b);
g = gcd(a, ji), ji /= g, a /= g;
a *= b;
g = gcd(a, ji), ji /= g, a /= g;
a *= b;
g = gcd(a, ji), ji /= g, a /= g;
if (ji > 1) {
puts("No");
continue;
}
for (l = 1, r = 1000001; l < r;) {
mid = ((l + r) >> 1);
t = mid * mid * mid;
if (t < ji2)
l = mid + 1;
else
r = mid;
}
if (l * l * l != ji2)
puts("No");
else
puts("Yes");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
long long gcd(long long a, long long b) {
long long c;
while (b) {
c = a % b;
a = b;
b = c;
}
return a;
}
int main() {
int t;
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
long long tmp = a * b;
tmp = pow(tmp, 1.0 / 3.0);
if (tmp * tmp * tmp != a * b) {
tmp++;
}
if (tmp * tmp * tmp != a * b) {
cout << "No" << endl;
continue;
}
if (tmp > a || tmp > b) {
cout << "No" << endl;
continue;
}
if (gcd(tmp, a) != tmp || gcd(tmp, b) != tmp) {
cout << "No" << endl;
continue;
}
cout << "Yes" << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const int N = 31;
int d[N][N];
vector<int> p;
bool check(int a) {
for (int i = 2; 1ll * i * i <= a; ++i) {
if (a % i == 0) return 0;
}
return 1;
}
set<int> sq;
int main() {
cout.setf(ios::showpoint | ios::fixed);
cout.precision(20);
memset(d, 0, sizeof(d));
d[0][0] = 1;
for (int i = int(2); i < int(1000); ++i) {
if (check(i)) {
p.push_back(i);
}
}
for (int i = int(0); i < int(N); ++i) {
for (int j = int(0); j < int(N); ++j) {
if (!d[i][j]) continue;
for (int k = int(0); k < int(N); ++k) {
if (i + 2 * k < N && j + k < N) {
d[i + 2 * k][j + k] = N;
}
if (i + k < N && j + 2 * k < N) {
d[i + k][j + 2 * k] = N;
}
}
}
}
for (int i = 1; i * i <= 1000000000; ++i) {
if (check(i)) sq.insert(i * i);
}
int n;
cin >> n;
for (int i = int(0); i < int(n); ++i) {
int a, b;
scanf("%d %d", &a, &b);
bool ok = 1;
for (auto prime : p) {
int kola = 0, kolb = 0;
while (a % prime == 0) {
a /= prime, kola++;
}
while (b % prime == 0) {
b /= prime, kolb++;
}
if (!d[kola][kolb]) {
ok = 0;
break;
}
}
if (ok &&
((a == b && a == 1) || (sq.find(a) != sq.end() && 1ll * b * b == a) ||
(sq.find(b) != sq.end() && 1ll * a * a == b))) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool solve() {
int a, b;
scanf("%d %d", &a, &b);
int both = int(floor(pow((double)a * b, 1.0 / 3) + 0.5));
if (both == 0) return a == 1 && b == 1;
if (a % both != 0 || b % both != 0) return false;
if ((long long)a * b != (long long)both * both * both) return false;
long long A = a / both;
long long B = b / both;
if (B * B * A != b || A * A * B != a) return false;
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
if (solve())
puts("Yes");
else
puts("No");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int a, b;
scanf("%d%d", &a, &b);
int64_t x = a * (int64_t)b, y = cbrtl(x) + 0.5;
puts(y * y * y == x && a % y == 0 && b % y == 0 ? "Yes" : "No");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
unordered_set<int> cube;
for (int i = 1; i <= 1000; i++) cube.insert(i * i * i);
int N;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
int a, b, c, d;
scanf("%d%d", &a, &b);
int t = gcd(a, b);
c = a / t;
d = b / t;
long long q = 1LL * c * d;
if (t % q != 0) {
printf("No\n");
} else {
int r = t / q;
if (cube.find(r) == cube.end())
printf("No\n");
else
printf("Yes\n");
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
void solve(istream& cin, ostream& cout) {
int n;
cin >> n;
for (int in = (0); in < int(n); ++in) {
lint a, b;
cin >> a >> b;
lint c = a * b;
lint x = lint(pow(c, 1.0 / 3)) - 3;
x = max<lint>(1, x);
bool ok = false;
while (x * x * x <= c) {
if (x * x * x == c) {
ok = true;
break;
}
x++;
}
if (ok && a % x == 0 && b % x == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve(cin, cout);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> cube;
int main() {
int t, u, v;
long long int x;
for (long long int i = 1; i <= 1000000; i++) cube.push_back(i * i * i);
scanf("%d", &t);
while (t--) {
scanf("%d %d", &u, &v);
x = (long long int)u * v;
int p = lower_bound(cube.begin(), cube.end(), x) - cube.begin() + 1;
if (cube[p - 1] != x)
puts("No");
else {
if ((u % p) || (v % p))
puts("No");
else
puts("Yes");
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
const int mod = 1e9 + 7;
int n, m, k;
const int MX = 1000010;
int sito[MX + 5];
vector<int> primes;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int a, b;
cin >> a >> b;
long long int ilo = a * b;
long long int x = 1, y = MX;
while (x < y) {
long long int sr = (x + y) / 2;
if (sr * sr * sr < ilo)
x = ++sr;
else
y = sr;
}
bool odp = 1;
if (x * x * x != ilo)
odp = 0;
else {
if (a % x != 0) odp = 0;
if (b % x != 0) odp = 0;
}
if (odp)
cout << "Yes\n";
else
cout << "No\n";
}
}
| 7 | CPP |
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from math import pow
# ------------------------------
def main():
for _ in range(N()):
a, b = RL()
mt = a*b
res = round(pow(mt, 1/3))
if res**3==mt and a%res==0 and b%res==0:
print('Yes')
else:
print('No')
if __name__ == "__main__":
main() | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void boost() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long cubic_root(long long x) {
long long l = 0, r = 2000005;
while (l != r) {
long long m = (l + r + 1) / 2;
if (m * m * m > x)
r = m - 1;
else
l = m;
}
return l;
}
int main(void) {
boost();
long long t;
cin >> t;
while (t--) {
long long a, b, flag = 0;
cin >> a >> b;
long long x = a * b;
long long n = cubic_root(x);
long long t1 = n * n * n;
if (t1 != x) {
flag = 1;
}
if (flag)
cout << "NO"
<< "\n";
else {
if (a % n == 0 && b % n == 0) {
cout << "YES"
<< "\n";
} else
cout << "NO"
<< "\n";
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
const long long inf = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
const int N = 2e6 + 1;
void solve() {
long long a, b;
cin >> a >> b;
long long target = a * b;
long long l = 0;
long long r = 1e6, mid, d;
bool k = false;
while (l <= r) {
mid = l + (r - l) / 2;
d = mid * mid * mid;
if (d == target) {
k = true;
break;
}
if (d < target) {
l = mid + 1;
} else {
r = mid - 1;
}
}
if (k == true && a % mid == 0 && b % mid == 0) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.second == b.second) return a.first < b.first;
return a.second < b.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long m, a, ans, c, g, d;
cin >> m;
while (m--) {
cin >> a >> c;
ans = 0;
for (int b = 1e6; b >= 1; b /= 2) {
while ((ans + b) * (ans + b) * (ans + b) <= c * a) ans += b;
}
if (ans * ans * ans == c * a) {
if (c % ans == 0 && a % ans == 0)
cout << "yes";
else
cout << "no";
} else
cout << "no";
cout << "\n";
}
return 0;
}
| 7 | CPP |
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
avl=AvlTree()
#-----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default='z', func=lambda a, b: min(a ,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left)/ 2)
# Check if middle element is
# less than or equal to key
if (arr[mid]<=key):
count = mid+1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def countGreater( arr,n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
for i in range(int(input())):
a,b=map(int,input().split())
#c=a*b
l=int((a*b)**(1/3)+0.5)
if l**3==a*b and a%l==0 and b%l==0:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 16;
int lpf[N];
void init() {
memset(lpf, -1, sizeof(lpf));
for (int n = 2; n < N; n++) {
if (lpf[n] == -1) {
lpf[n] = n;
if (n < N / n) {
for (int m = n * n; m < N; m += n) {
if (lpf[m] == -1) lpf[m] = n;
}
}
}
}
}
inline int cbrt(long long n) {
int lo = 1, hi = 1000000;
while (lo <= hi) {
int mi = (lo + hi) / 2;
long long tmp = mi * 1LL * mi * mi;
if (tmp < n)
lo = mi + 1;
else if (tmp > n)
hi = mi - 1;
else
return mi;
}
return -1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(32);
init();
int n;
cin >> n;
while (n--) {
long long a, b;
cin >> a >> b;
int x = cbrt(a * b);
if (x == -1) {
cout << "No" << '\n';
} else {
bool flg = true;
while (x > 1) {
int p = lpf[x];
while (x % p == 0) {
x /= p;
}
int cnt1 = 0;
int cnt2 = 0;
while (a % p == 0) {
a /= p;
cnt1++;
}
while (b % p == 0) {
b /= p;
cnt2++;
}
int x = (cnt1 + cnt2) / 3;
if (x > cnt1 || x > cnt2) {
flg = false;
break;
}
}
if (flg)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, i, x, y;
scanf("%I64d ", &a);
while (a--) {
scanf("%I64d %I64d", &x, &y);
i = ceil(cbrt(x * y));
if (x % i == 0 && y % i == 0 && (x * y) % i == 0) {
printf("Yes\n");
} else
printf("No\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t-- > 0) {
long long a, b;
cin >> a >> b;
string res = "No\n";
long long raiz = cbrt(a * b);
for (long long i = max(1LL, raiz - 2); i < raiz + 2; ++i) {
if (a * b == i * i * i && a % i == 0 && b % i == 0) {
res = "Yes\n";
break;
}
}
cout << res;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long pow3(long long a, long long b, long long m = 1000000007) {
long long res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
void solve() {
long long a, b;
scanf("%lld %lld", &a, &b);
long long s = 0, e = 1e6 + 1;
while (s < e) {
long long m = (s + e) / 2;
if (m * m * m < a * b)
s = m + 1;
else
e = m;
}
if (s * s * s == a * b && a % s == 0 && b % s == 0)
printf("Yes\n");
else
printf("No\n");
}
int main() {
int q = 1;
scanf("%d", &q);
while (q--) {
solve();
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
map<T, long long int> factorize(T x) {
map<T, long long int> res;
for (long long int i = 2; i * i <= x; i++) {
while (x % i == 0) {
x /= i;
res[i]++;
}
}
if (x != 1) res[x]++;
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int qq;
cin >> qq;
while (qq--) {
long long int a, b;
cin >> a >> b;
if (a * a % b || b * b % a) {
printf("No\n");
continue;
}
long long int left = 0, right = 1e6 + 1;
while (right - left > 1) {
long long int mid = (left + right) / 2;
if (mid * mid * mid <= a * b) {
left = mid;
} else {
right = mid;
}
}
if (left * left * left == a * b) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b, long long int m) {
long long int ans = 1;
while (b) {
if (b & 1) {
ans = ((ans % m) * (a % m)) % m;
}
a = ((a % m) * (a % m)) % m;
b = b >> 1;
}
return ans;
}
long long int powe(long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b & 1) {
ans = a * ans;
}
a = a * a;
b = b >> 1;
}
return ans;
}
long long int ncr(long long int n, long long int r) {
r = ((r < n - r) ? (r) : (n - r));
long long int ans = 1;
for (int i = 0; i < r; i++) {
ans *= (n - i);
ans /= (i + 1);
}
return ans;
}
long long int spf[1000005];
void sieve() {
long long int n = 1000002;
for (int i = 2; i <= n; i += 2) {
spf[i] = 2;
}
for (int i = 3; i <= n; i += 2) {
spf[i] = i;
}
for (int i = 3; i * i <= n; i += 2) {
if (spf[i] == i) {
for (int j = i * i; j <= n; j += i) {
if (spf[j] == j) {
spf[j] = i;
}
}
}
}
}
set<long long int> calc(long long int n) {
long long int newn = n;
set<long long int> facors;
while (n % 2 == 0) {
facors.insert(2);
n = n / 2;
}
for (int i = 3; i * i <= n; i += 2) {
while (n % i == 0) {
facors.insert(i);
n = n / i;
}
}
if (n > 1) {
facors.insert(n);
}
set<long long int> x1;
for (auto i : facors) {
if (newn / i >= 2) x1.insert(newn - i + 1);
}
return x1;
}
void solve() {
long long int a, b;
cin >> a >> b;
long long int c = cbrt(a * b);
if (c * c * c < a * b) {
c++;
}
if (c * c * c == a * b) {
if (a % c != 0) {
cout << "NO\n";
return;
}
if (b % c != 0) {
cout << "NO\n";
return;
}
} else {
cout << "NO\n";
return;
}
cout << "YES\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long int t = 1;
cin >> t;
while (t > 0) {
solve();
t--;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int a, b;
cin >> a >> b;
long long int prod = a * b;
long long int l = 1;
long long int r = 1e6;
long long int mid;
while (l <= r) {
mid = (l + r) / 2;
if (mid * mid * mid == prod) {
break;
}
if (mid * mid * mid < prod) {
l = mid + 1;
} else {
r = mid - 1;
}
}
if (mid * mid * mid == prod && a % mid == 0 && b % mid == 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll a, b, x, y, m;
while (n--) {
cin >> a >> b;
x = 0, y = 1000000;
while (x <= y) {
m = x + (y - x) / 2;
if (m * m * m == a * b) {
x = m;
break;
}
if (m * m * m > a * b)
y = m - 1;
else
x = m + 1;
}
if (a % x or b % x)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
int cnt = 1;
while (T--) {
long long A, B, C;
scanf("%lld %lld", &A, &B);
C = A * B;
long long sm = (long long)(pow(C, 1 / 3.0) + 0.5);
if (sm * sm * sm != C || sm > min(A, B) || A % sm || B % sm)
printf("No\n");
else
printf("Yes\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, x, y, w, path_w, m, a[100500];
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int main() {
cin >> n;
for (i = 0; i < n; i++) {
scanf("%d %d", &x, &y);
int g = gcd(x, y);
int dlfjl = x / g, y1 = y / g;
if (y % (1LL * y1 * y1 * dlfjl) != 0 ||
x % (1LL * dlfjl * dlfjl * y1) != 0) {
printf("No\n");
continue;
}
y /= (1LL * y1 * y1 * dlfjl);
x /= (1LL * dlfjl * dlfjl * y1);
if (x != y) {
printf("No\n");
continue;
}
int tmp = exp(1. / 3 * log(x));
tmp--;
while (1LL * tmp * tmp * tmp < x) tmp++;
if (tmp * tmp * tmp == x)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long x, y, le = 1, ri = 1e6, mi, o;
scanf("%lld%lld", &x, &y);
while (le + 1 < ri) {
mi = (le + ri) >> 1;
if (mi * mi * mi > x * y)
ri = mi;
else
le = mi;
}
if (le * le * le == x * y)
o = le;
else
o = ri;
if (o * o * o != x * y) {
puts("No");
continue;
}
if (x % o == 0 && y % o == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int bin(long long a, long long b) {
long long t = a * b;
long long l = 1, h = 1E6, m;
while (l <= h) {
m = (l + h) / 2;
if (m * m * m == t) return m;
if (m * m * m > t) {
h = m - 1;
} else {
l = m + 1;
}
}
return 0;
}
int main() {
long long a, b;
int n, i, c = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lld %lld", &a, &b);
c = bin(a, b);
if (c && a % c == 0 && b % c == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
void fileio() {}
vector<vector<long long int>> g;
long long int cube_root(long long int x) {
long long int lo = 0, hi = 1e6 + 10;
while (lo <= hi) {
long long int m = (lo + hi) / 2;
long long int val = m * m * m;
if (val == x) return m;
if (val > x) {
hi = m - 1;
} else {
lo = m + 1;
}
}
return -1;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
fileio();
long long int t;
cin >> t;
while (t-- > 0) {
long long int a, b;
cin >> a >> b;
long long int x = a * b;
long long int c = cube_root(x);
if (c == -1) {
cout << "NO";
cout << '\n';
continue;
}
if (a % c != 0 or b % c != 0) {
cout << "NO";
cout << '\n';
continue;
}
cout << "YES";
cout << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, x;
int n;
long long s3(long long x) {
long long l = 1, r = 1e6, res = -1;
while (l <= r) {
long long mid = (l + r) >> 1, val = mid * mid * mid;
if (val == x) return mid;
if (val < x) l = mid + 1;
if (val > x) r = mid - 1;
}
return -1;
}
int main() {
scanf("%d", &n);
while (n--) {
scanf("%I64d%I64d", &a, &b);
c = a * b;
x = s3(c);
if (x != -1 && a % x == 0 && b % x == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for tc in range(t):
a, b = map(int, input().split())
cbrt = round(pow(a*b, 1/3))
if pow(cbrt, 3) == a*b:
if a % cbrt == b % cbrt == 0:
print("Yes")
continue
print("No") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long rt3(long long x) {
long long l = 0, r = 1e6;
for (int i = 0; i < 30; i++) {
long long h = (l + r) / 2;
if (h * h * h < x) {
l = h;
} else {
r = h;
}
}
return r;
}
long long min(long long a, long long b) { return a < b ? a : b; }
bool possible(long long a, long long b) {
long long t = rt3(a * b);
if (t * t * t != a * b) {
return false;
} else if (a % t != 0) {
return false;
} else if (b % t != 0) {
return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
if (possible(a, b)) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long x, long long y) {
while (y != 0) {
long long t = x % y;
x = y;
y = t;
}
return x;
}
long long n, a, b;
long long cs;
bool calc() {
scanf("%lld %lld", &a, &b);
long long g = GCD(a, b);
long long p = a / g;
long long q = b / g;
long long pq = p * q;
bool ret = (g % pq == 0);
if (ret) {
long long r = g / pq;
long long i = 1;
while (i * i * i < r) {
i++;
}
if (i * i * i == r) return true;
}
return false;
}
int main() {
scanf("%lld", &n);
while (cs < n) {
cs++;
bool ans = calc();
if (ans)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
const long long N = 500500;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<long long> cube;
for (long long i = 1; i <= 1e6; i++) {
cube.push_back(i * i * i);
}
long long T;
cin >> T;
while (T--) {
long long a, b;
cin >> a >> b;
bool ok = false;
auto it = lower_bound((cube).begin(), (cube).end(), a * b);
if (it != cube.end()) {
long long cr = (it - cube.begin() + 1);
if (a % cr == 0 && b % cr == 0) {
ok = true;
}
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXR = 1000005;
long long cubic_root(long long x) {
long long l = 0, r = MAXR;
while (l != r) {
long long m = (l + r + 1) / 2;
if (m * m * m > x)
r = m - 1;
else
l = m;
}
return l;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
long long a, b;
scanf("%lld %lld", &a, &b);
long long x = cubic_root(a * b);
if (x * x * x != a * b)
puts("No");
else if (a % x == 0 && b % x == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int t;
long long a, b;
long long cubic_root(long long x) {
long long lo = 1, hi = 1e6, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (mid * mid * mid < x)
lo = mid + 1;
else
hi = mid;
}
return lo;
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%lld %lld", &a, &b);
long long crt = cubic_root(a * b);
if (crt * crt * crt == a * b && a % crt == 0 && b % crt == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;
bool iscube(int x) {
int low = 1;
int high = 1000;
int mid;
int ans = 1;
while (low <= high) {
mid = (low + high) / 2;
if (mid * mid * mid <= x) {
ans = mid;
low = mid + 1;
} else {
high = mid - 1;
}
}
return ans * ans * ans == x;
}
int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
int n;
cin >> n;
while (n--) {
int a, b;
scanf("%d%d", &a, &b);
int d = gcd(a, b);
int aa = a / d;
int bb = b / d;
if (d % (aa * bb) == 0 && iscube(d / aa / bb)) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool vis[100010];
int pr[100010], e;
void Shai() {
vis[1] = true;
for (long long i = 2; i <= 1000ll; i++) {
if (!vis[i]) {
pr[++e] = i;
for (long long j = i * i; j <= 1000ll; j += i) {
vis[j] = true;
}
}
}
}
int n, cnta[100010];
int main() {
Shai();
int x, y;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &x, &y);
int X = x;
for (int j = 1; j <= e; ++j) {
if (X % pr[j] == 0) {
while (X % pr[j] == 0) {
X /= pr[j];
++cnta[j];
}
}
}
bool lose = 0;
for (int j = 1; j <= e; ++j) {
int cntb = 0;
if (y % pr[j] == 0) {
while (y % pr[j] == 0) {
y /= pr[j];
++cntb;
}
}
if ((cnta[j] + cntb) % 3 != 0) {
lose = 1;
break;
} else if (min(cnta[j], cntb) * 2 < max(cnta[j], cntb)) {
lose = 1;
break;
}
}
if (!(X == 1 && y == 1) && !((long long)min(X, y) * (long long)min(X, y) ==
(long long)max(X, y))) {
lose = 1;
}
for (int j = 1; j <= e; ++j) {
cnta[j] = 0;
}
if (!lose)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
long long x, y, m;
double ret;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%lld %lld", &x, &y);
ret = pow((double)(x * y), 1.0 / 3.0);
m = round(ret);
if (m * m * m != (x * y) || x % m || y % m)
puts("No");
else
puts("Yes");
}
return 0;
}
| 7 | CPP |
import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
for _ in range(int(input())):
a, b = map(int, input().split())
q = a * b
t = round(q ** (1 / 3))
if t * t * t == q and a % t == b % t == 0:
print('YES')
else:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, k, u, v;
map<int, bool> OK;
int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }
void solve() {
scanf("%d%d", &a, &b);
k = GCD(a, b);
u = a / k;
v = b / k;
if (k % u != 0) {
puts("No");
return;
} else
k /= u;
if (k % v != 0) {
puts("No");
return;
} else
k /= v;
if (!OK[k]) {
puts("No");
return;
}
puts("Yes");
}
void init() {
for (int i = 1; i <= 1000; i++) OK[i * i * i] = true;
}
int main() {
init();
int nT;
scanf("%d", &nT);
while (nT--) solve();
}
| 7 | CPP |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int number;
std::cin >> number;
while (number--) {
int a, b;
std::cin >> a >> b;
int const c = (int)std::round(std::cbrt(a * (int64_t)b));
std::cout << ((int64_t)c * c * c == (int64_t)a * b and a % c == 0 and
b % c == 0
? "Yes\n"
: "No\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long ff(long long a) {
long long le = 1, ri = 1000010;
while (le <= ri) {
long long mi = (le + ri) / 2;
if (mi * mi * mi > a)
ri = mi - 1;
else
le = mi + 1;
}
return ri;
}
int main() {
int _;
scanf("%d", &_);
while (_--) {
int a, b;
scanf("%d%d", &a, &b);
long long xy = ff((long long)a * b);
long long x = a / xy;
long long y = b / xy;
if (a == x * x * y && b == x * y * y)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
long long ans = 1;
while (p) {
if (p & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
p /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
const int N = 1000002;
int sieve[N], prime_facs[N];
int main() {
for (int i = 2; i < N; i++)
if (sieve[i] == 0) {
for (int j = i; j < N; j += i) {
sieve[j] = 1;
if (prime_facs[j] == 0) prime_facs[j] = i;
}
}
int t;
scanf("%d", &t);
while (t--) {
long long a, b;
scanf("%lld%lld", &a, &b);
long long prod = a * b;
long long lo = 1, hi = 1000 * 1000 + 1, ans = 0;
ans = cbrt(prod);
while (ans * ans * ans < prod) ans++;
while (ans * ans * ans > prod) ans--;
if (ans * ans * ans != prod) {
printf("No\n");
continue;
}
bool bad = false;
while (ans != 1) {
int p = prime_facs[ans];
int c1 = 0, c2 = 0, c3 = 0;
while (a % p == 0) {
a /= p;
c1++;
}
while (b % p == 0) {
b /= p;
c2++;
}
while (ans % p == 0) {
ans /= p;
c3++;
}
if ((2 * c1 - c2) % 3 != 0 || (2 * c1 < c2)) bad = true;
swap(c1, c2);
if ((2 * c1 - c2) % 3 != 0 || (2 * c1 < c2)) bad = true;
if (bad) break;
}
if (!bad)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
long long a, b;
cin >> n;
while (n--) {
cin >> a >> b;
long long c = a * b;
bool ok = false;
long long left = 1, right = 1000001;
long long ans;
while (left <= right) {
long long mid = (left + right) / 2;
long long now = mid * mid * mid;
if (now == c) {
ans = mid;
ok = 1;
break;
}
if (now > c) right = mid - 1;
if (now < c) left = mid + 1;
}
if (!ok) {
cout << "No" << '\n';
} else {
if (a % ans == 0 && b % ans == 0) {
cout << "Yes" << '\n';
} else
cout << "No" << '\n';
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = int(1e6) + 5;
long long cubic_root(long long x) {
long long l = 0, r = INF, med, answ;
while (l <= r) {
med = l + (r - l) / 2;
if (med * med * med >= x) {
answ = med;
r = med - 1;
} else {
l = med + 1;
}
}
return answ;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, a, b, x;
cin >> n;
while (n--) {
cin >> a >> b;
x = cubic_root(a * b);
if (1ll * x * x * x == 1ll * a * b && a % x == 0 && b % x == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c[1234567], d[1234567], c1[1234][1234], e[1234567], n, j, i, l,
r, x, y, k, ans;
bool used[1234567];
long long T;
char ch[1234][1234];
long long vis[1234][1234];
vector<long long> v[1234567], v1;
string s1[1234567];
int main() {
cin >> T;
while (T--) {
scanf("%lld%lld", &x, &y);
n = x * y;
a = pow(n, 1.0 / 3) + 0.5;
if (a * a * a != n || x % a > 0 || y % a > 0) {
puts("NO");
} else
puts("YES");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 0;
char ch = getchar();
while (ch < '0' || '9' < ch) f |= ch == '-', ch = getchar();
while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return f ? -x : x;
}
int q[31709], tot;
bool b[31709];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
for (int i = 2; i <= 31700; i++)
if (!b[i]) {
q[++tot] = i;
for (int a = i + i; a <= 31700; a += i) b[a] = true;
}
int T = read();
while (T--) {
int a = read(), b = read(), c = gcd(a, b);
bool F = true;
if (c == 1 && a + b != 2) {
puts("No");
continue;
}
if (c == a && a == b) {
for (int o = 1; o <= tot; o++)
if (q[o] > 1000)
break;
else if (a % q[o] == 0 && b % q[o] == 0) {
int aa = 0, bb = 0;
while (a % q[o] == 0) a /= q[o], aa++;
while (b % q[o] == 0) b /= q[o], bb++;
if (aa < bb) swap(aa, bb);
int tmp = aa - bb;
aa -= tmp + tmp, bb -= tmp;
if (aa < 0 || aa % 3 != 0) {
F = false;
break;
}
} else if ((a % q[o] == 0) != (b % q[o] == 0)) {
F = false;
break;
} else if ((a == 1) != (b == 1)) {
F = false;
break;
} else if ((a == 1) && (b == 1))
break;
if (a != 1 || b != 1) F = false;
puts(F ? "Yes" : "No");
continue;
}
for (int o = 1; o <= tot; o++)
if (a % q[o] == 0 && b % q[o] == 0) {
int aa = 0, bb = 0;
while (a % q[o] == 0) a /= q[o], aa++;
while (b % q[o] == 0) b /= q[o], bb++;
if (aa < bb) swap(aa, bb);
int tmp = aa - bb;
aa -= tmp + tmp, bb -= tmp;
if (aa < 0 || aa % 3 != 0) {
F = false;
break;
}
} else if ((a % q[o] == 0) != (b % q[o] == 0)) {
F = false;
break;
} else if ((a == 1) != (b == 1)) {
F = false;
break;
} else if ((a == 1) && (b == 1))
break;
if (a != 1 || b != 1) F = false;
puts(F ? "Yes" : "No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
long long int a, b;
cin >> a >> b;
long long int p = a * b;
long long int st = 1;
long long int en = 1e6;
long long int ans = -1;
while (st <= en) {
long long int mid = st + en;
mid /= 2;
long long int check = mid * mid * mid;
if (check < p) {
st = mid + 1;
} else if (check == p) {
ans = mid;
break;
} else
en = mid - 1;
}
if (ans != -1 && a % ans == 0 && b % ans == 0) {
cout << "YES\n";
} else
cout << "NO\n";
}
cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
<< '\n';
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
int n;
scanf("%d", &n);
while (n--) {
long long a, b;
scanf("%lld%lld", &a, &b);
long long c = cbrt(a * b);
long long aa = a / c;
long long bb = b / c;
if (aa * aa * bb == a && bb * bb * aa == b) {
puts("Yes");
} else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXR = 1000005;
long long cubic_root(long long x) {
long long l = 0, r = MAXR;
while (l != r) {
long long m = (l + r + 1) / 2;
if (m * m * m > x)
r = m - 1;
else
l = m;
}
return l;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
long long a, b;
scanf("%I64d %I64d", &a, &b);
long long x = cubic_root(a * b);
if (x * x * x != a * b)
puts("No");
else if (a % x == 0 && b % x == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = (0); i < (n); i++) {
int a, b;
scanf("%d%d", &a, &b);
int ret = -1;
for (int l = 1, r = 1000000, mid = (l + r) >> 1; l <= r; mid = (l + r) >> 1)
if (1ll * mid * mid * mid >= 1ll * a * b)
r = (ret = mid) - 1;
else
l = mid + 1;
if (!~ret || 1ll * ret * ret * ret != 1ll * a * b) {
printf("No\n");
continue;
}
if (a % ret != 0 || b % ret != 0) {
printf("No\n");
} else {
printf("Yes\n");
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
s << "[";
for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
s << "]";
return s;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
ll a, b;
scanf("%lld %lld", &a, &b);
ll ok = 0, ng = 1500000LL;
while (ng - ok > 1) {
ll mid = (ng + ok) / 2;
if (mid * mid * mid <= a * b) {
ok = mid;
} else {
ng = mid;
}
}
ll c = ok;
if (c * c * c == a * b && a % c == 0 && b % c == 0) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
| 7 | CPP |
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
for t in range (int(input())):
a,b=map(int,input().split())
p=a*b
#print(p)
c=int(round(p**(1./3)))
#print (c)
if c**3==p and a%c==0 and b%c==0:
print("Yes")
else:
print("No") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
const long long inf = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
const int N = 2e6 + 1;
void solve() {
long long a, b;
cin >> a >> b;
long long target = a * b;
long long l = 1;
long long r = 1e6, mid, d;
bool k = false;
while (l <= r) {
mid = l + (r - l) / 2;
d = mid * mid * mid;
if (d == target) {
k = true;
break;
}
if (d < target) {
l = mid + 1;
} else {
r = mid - 1;
}
}
if (k == true && a % mid == 0 && b % mid == 0) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t random_long(long long l = LLONG_MIN, long long r = LLONG_MAX) {
uniform_int_distribution<int64_t> generator(l, r);
return generator(rng);
}
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
const long long inf = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
const int N = 2e6 + 1;
void solve() {
long long a, b;
cin >> a >> b;
long long target = a * b;
long long l = 1;
long long r = 1e6, mid, d;
bool k = false;
while (l <= r) {
mid = (l + r) >> 1;
d = mid * mid * mid;
if (d == target) {
k = true;
break;
}
if (d < target) {
l = mid + 1;
} else {
r = mid - 1;
}
}
if (k == true && a % mid == 0 && b % mid == 0) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| 7 | CPP |
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
avl=AvlTree()
#-----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default='z', func=lambda a, b: min(a ,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left)/ 2)
# Check if middle element is
# less than or equal to key
if (arr[mid]<=key):
count = mid+1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def countGreater( arr,n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
for i in range(int(input())):
a,b=map(int,input().split())
c=a*b
l=int(c**(1./3)+0.5)
if l**3==a*b and a%l==0 and b%l==0:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const long long LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e6 + 10;
map<long long, long long> rt;
int q;
long long a, b;
int main() {
for (long long i = 1; i < N; i++) rt[i * i * i] = i;
scanf("%d", &q);
while (q--) {
scanf("%lld%lld", &a, &b);
long long r = rt[a * b];
printf("%s\n", r and a % r == 0 and b % r == 0 ? "Yes" : "No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long x, long long y) {
if (y == 0) return x;
return GCD(y, x % y);
}
long long n, a, b;
long long cs;
bool calc() {
scanf("%lld %lld", &a, &b);
long long g = GCD(a, b);
long long p = a / g;
long long q = b / g;
long long pq = p * q;
bool ret = (g % pq == 0);
if (ret) {
long long r = g / pq;
long long i = 1;
while (i * i * i < r) {
i++;
}
if (i * i * i == r) return true;
}
return false;
}
int main() {
scanf("%lld", &n);
while (cs < n) {
cs++;
bool ans = calc();
if (ans)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1e9 + 7;
long long MOD = 998244353;
unsigned long long ncr(long long n, long long k) {
if (k > n) return 1ll * 0;
unsigned long long res = 1;
if (k > n - k) k = n - k;
for (long long i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
res = res;
}
return res;
}
bool prime(unsigned long long num) {
bool flag = true;
for (unsigned long long i = 2; i * i <= num; i++) {
if (num % i == 0) {
flag = false;
break;
}
}
return flag;
}
long long ipow(long long base, long long exp) {
if (exp == 0) return 1ll * 1;
long long result = 1;
for (;;) {
if (exp & 1) {
result *= base;
result = result % MOD;
}
exp >>= 1;
if (!exp) break;
base *= base;
base = base % MOD;
}
return result % MOD;
}
long long abs(long long a, long long b) {
if ((a - b) > 0)
return (a - b);
else
return (b - a);
}
long long add(long long a, long long b) {
a += b;
if (a >= MOD)
a -= MOD;
else if (a < 0)
a += MOD;
return a;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long der(long long k) {
long long res = 0;
long long fact = 1;
for (long long i = 2; i <= k; i++) fact *= i;
long long s = 1;
long long j = 1;
for (long long i = 2; i <= k; i++) {
j = j * i;
long long first = (fact / j) * s;
res += first;
s = s * (-1);
}
return res;
}
vector<long long> p;
vector<long long> _prime(long long a) {
vector<long long> v;
for (long long i = 2; i * i <= a; i++) {
if (a % i == 0) {
v.push_back(i);
while (a % i == 0) a /= i;
}
}
if (a != 1) v.push_back(a);
return v;
}
long long cubic_root(long long x) {
long long l = 0, r = 1000000;
while (l != r) {
long long m = (l + r + 1) / 2;
if (m * m * m > x)
r = m - 1;
else
l = m;
}
return l;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
while (n--) {
long long a, b;
cin >> a >> b;
long long c = a * b;
long long k = cubic_root(c);
bool flag = false;
if (k * k * k == c && a % k == 0 && b % k == 0) flag = true;
if (flag == true) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, i, x, y;
scanf("%I64d ", &a);
while (a--) {
scanf("%I64d %I64d", &x, &y);
i = ceil(cbrt(x * y));
if (x % i == 0 && y % i == 0 && (x * y) == i * i * i) {
printf("Yes\n");
} else
printf("No\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b;
bool check(long long x) {
long long l = 0, r = 1000000;
while (l != r) {
long long m = (l + r + 1) / 2;
if (m * m * m > x) {
r = m - 1;
} else {
l = m;
}
}
bool ok = (l * l * l == a * b);
return (ok && !(a % l) && !(b % l));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
while (n--) {
cin >> a >> b;
if (check(a * b)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
long long a, b;
cin >> a >> b;
long long pro = (a * b);
long long c = cbrt((long double)(pro));
if (c * c * c != pro)
cout << "No" << '\n';
else if (a % c == 0 && b % c == 0)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
long long x, y;
long long gcd(long long x, long long y) {
if (!y) return x;
return gcd(y, x % y);
}
bool check() {
double x2 = log(x), y2 = log(y);
double t1 = (2 * y2 - x2) / 3, t2 = (2 * x2 - y2) / 3;
t1 = exp(t1);
t2 = exp(t2);
long long s1 = (t1 + 0.5), s2 = t2 + 0.5;
if (fabs(t1 - s1) < 1e-6 && fabs(t2 - s2) < 1e-6) return 1;
return 0;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &x, &y);
if (check())
puts("Yes");
else
puts("No");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long x, y;
scanf("%I64d%I64d", &x, &y);
long long t = x * y;
bool flag = false;
long long l = 1, r = 1e6 + 10, m;
while (l <= r) {
m = (l + r) / 2;
if (m * m * m == t) {
flag = true;
break;
} else if (m * m * m > t) {
r = m - 1;
} else {
l = m + 1;
}
}
if (flag) {
if (x % m != 0 || y % m != 0)
puts("NO");
else
puts("Yes");
} else
puts("No");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;
ll INF = 1LL << 60;
ll HI = 1000005;
ll cubic_root(ll x) {
ll lo = 0, hi = HI;
while (lo < hi) {
ll m = lo + ((hi - lo + 1) / 2);
if (m * m * m > x)
hi = m - 1;
else
lo = m;
}
return lo;
}
ll a, b, ab, cuberoot;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
while (n--) {
cin >> a >> b;
ab = a * b;
cuberoot = cubic_root(ab);
if (cuberoot * cuberoot * cuberoot != ab) {
cout << "No\n";
continue;
}
if (a % cuberoot == 0 && b % cuberoot == 0) {
cout << "Yes\n";
continue;
}
cout << "No\n";
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Maxk = 1005;
string mul(string a, string b) {
int res[Maxk];
memset(res, 0, sizeof(res));
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < a.length(); i++) {
for (int j = 0; j < b.length(); j++) {
res[i + j] += (a[i] - '0') * (b[j] - '0');
}
}
for (int i = 0; i < Maxk; i++) {
if (res[i] >= 10) {
res[i + 1] += (res[i] / 10);
res[i] %= 10;
}
}
string ret;
bool flag = false;
for (int i = Maxk - 1; i >= 0; i--) {
if (flag || res[i]) {
flag = true;
ret = ret + (char)(res[i] + '0');
}
}
if (ret == "") ret = "0";
return ret;
}
string add(string a, string b) {
if (a.length() < b.length()) swap(a, b);
while (a.length() != b.length()) {
b = '0' + b;
}
for (int i = a.length() - 1; i >= 0; i--) {
a[i] += (b[i] - '0');
if (a[i] > '9' && i) {
a[i] -= 10;
a[i - 1]++;
}
}
if (a[0] > '9') {
a[0] -= 10;
a = '1' + a;
}
return a;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
long long a, b;
a = (long long)read();
b = (long long)read();
long long c = a * b;
long long l = 0, r = 2e6;
while (r - l > 1) {
long long mid = (l + r) >> 1;
if (mid * mid * mid < c) {
l = mid;
} else {
r = mid;
}
}
long long v;
if (l * l * l == c) {
v = l;
} else if (r * r * r == c) {
v = r;
} else {
printf("No\n");
continue;
}
if (a % v == 0 && b % v == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long t, a, b;
scanf("%lld", &t);
while (t--) {
scanf("%lld%lld", &a, &b);
long long m = pow(a * b, (1.0 / 3)) + 0.5;
puts((m * m * m != a * b || a % m || b % m) ? "No" : "Yes");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
return __builtin_popcount(s);
}
template <class T>
inline T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
long long n, a, b;
long long fin(long long x) {
long long l = 0, r = 1e6;
while (l != r) {
long long mid = (l + r + 1) >> 1;
if (mid * mid * mid <= x) {
l = mid;
} else
r = mid - 1;
}
return l;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
while (n--) {
cin >> a >> b;
if (a > b) swap(a, b);
long long z = fin(a * b);
if (z * z * z != a * b)
cout << "No\n";
else if (a % z == 0 && b % z == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
while (n--) {
long long int a, b;
scanf("%lld %lld", &a, &b);
double t = pow(a * b, 1.0 / 3);
long long int x = t + 0.0001;
if (x * x * x == a * b && a % x == 0 && b % x == 0)
printf("YES\n");
else
printf("NO\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
long long r = 1;
for (; k; k >>= 1) {
if (k & 1) r = r * n % p;
n = n * n % p;
}
return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
long long r = sqrt(k) + 1;
while (r * r > k) r--;
return r;
}
inline long long icbrt(long long k) {
long long r = cbrt(k) + 1;
while (r * r * r > k) r--;
return r;
}
inline void addmod(int& a, int val, int p = MOD) {
if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 1e6 + 5;
int n;
int a[maxn];
vector<int> pos1;
vector<int> pos2;
int mn[maxn << 1];
int sm[maxn << 1];
void upd(int p, int val) {
p += 1 << 19;
mn[p] = sm[p] = val;
while (p > 1) {
p >>= 1;
sm[p] = sm[p << 1] + sm[p << 1 | 1];
mn[p] = min(mn[p << 1], sm[p << 1] + mn[p << 1 | 1]);
}
}
int check(int mi) {
for (int i = (0); i < (n); i++) {
upd(i, -a[i]);
}
for (int i = (0); i < (int((pos2).size())); i++) {
int ix = pos2[i];
upd(ix, 200);
}
int ptr = int((pos2).size()) - 1;
for (int x = (0); x < (int((pos1).size()) + 1); x++)
if (mi >= 1000 * x) {
int y = min(int((pos2).size()), (mi - 1000 * x) / 2000);
while (ptr >= y) {
int ix = pos2[ptr];
upd(ix, -2000);
ptr--;
}
if (x) {
int ix = pos1[x - 1];
upd(ix, 100);
}
int rm = mi - 1000 * x - 2000 * y;
if ((!x && a[0] == 1000) || (!y && a[0] == 2000)) {
upd(0, rm - a[0]);
} else {
upd(0, rm + a[0] / 10);
}
if (mn[1] >= 0) {
return 1;
}
}
return 0;
}
void solve() {
cin >> n;
for (int i = (0); i < (n); i++) {
cin >> a[i];
if (a[i] == 1000) {
pos1.push_back(i);
} else {
pos2.push_back(i);
}
}
int lo = 0, hi = 600000000;
while (lo < hi) {
int mi = lo + hi >> 1;
if (!check(mi)) {
lo = mi + 1;
} else {
hi = mi;
}
}
cout << (lo + hi >> 1) << "\n";
}
int main() {
int JUDGE_ONLINE = 1;
if (fopen("in.txt", "r")) {
JUDGE_ONLINE = 0;
assert(freopen("in.txt", "r", stdin));
} else {
ios_base::sync_with_stdio(0), cin.tie(0);
}
solve();
if (!JUDGE_ONLINE) {
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[300010];
long long dp[300010][42], ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 30; j++) dp[i][j] = 300000000000LL;
dp[0][0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j <= 30; j++) {
if (j + a[i] / 1000 <= 30)
dp[i + 1][j + a[i] / 1000] =
min(dp[i + 1][j + a[i] / 1000], dp[i][j] + a[i]);
if (j * 100 >= a[i])
dp[i + 1][j - a[i] / 100] = min(dp[i + 1][j - a[i] / 100], dp[i][j]);
else
dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + a[i] - j * 100);
}
ans = dp[n][0];
for (int i = 1; i <= 30; i++) ans = min(ans, dp[n][i]);
printf("%lld\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
const int maxn = 3e5 + 50;
const int inf = 0x3f3f3f3f;
int n, f[2][312], cur = 0;
inline void Update(int& x, int y) { x = std::min(x, y); }
int main(int argc, char* argv[]) {
scanf("%d", &n);
memset(f[cur], 0x3f, sizeof(f[cur]));
f[cur][0] = 0;
while (n--) {
int x, pre = cur;
cur ^= 1;
memset(f[cur], 0x3f, sizeof(f[cur]));
scanf("%d", &x);
for (int i = 0; i < 312; ++i)
if (f[pre][i] != inf) {
if (i + x / 100 < 312) Update(f[cur][i + x / 100], f[pre][i] + x);
int used = std::min(x, i * 10);
if (i - used / 10 < 312)
Update(f[cur][i - used / 10], f[pre][i] + x - used);
}
}
int ans = inf;
for (int i = 0; i < 312; ++i) ans = std::min(ans, f[cur][i]);
printf("%d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
void addmod(int &a, long long b) {
a = (a + b);
if (a >= 1000000007) a -= 1000000007;
}
void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
template <class T>
bool domin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool domax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
int gi() {
int a;
scanf("%d", &a);
return a;
}
long long gll() {
long long a;
scanf("%lld", &a);
return a;
}
int ans[2][34];
int main() {
int v = 1000000007;
fill_n(ans[0], 34, v);
fill_n(ans[1], 34, v);
ans[0][0] = 0;
int n = gi(), ix, nx;
for (int i = 0; i < n; i++) {
int x = gi() / 100;
int bo = x / 10;
ix = (i & 1);
nx = ix ^ 1;
fill_n(ans[nx], 34, v);
for (int j = 0; j < 34; j++)
if (ans[ix][j] < 1000000007) {
if (j < x) {
domin(ans[nx][j + bo], ans[ix][j] + x);
domin(ans[nx][0], ans[ix][j] + x - j);
} else if (j < 30) {
domin(ans[nx][j - x], ans[ix][j]);
domin(ans[nx][j + bo], ans[ix][j] + x);
} else {
domin(ans[nx][j - x], ans[ix][j]);
}
}
}
int fa = 1000000007;
for (int i = 0; i < 34; i++) {
domin(fa, ans[nx][i]);
}
cout << fa * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int a[N];
int f[45];
int g[45];
int n;
int ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] /= 100;
memset(f, 127 / 3, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
memset(g, 127 / 3, sizeof(g));
for (int j = 1; j <= a[i]; j++) g[0] = min(f[j] + a[i] - j, g[0]);
for (int j = a[i] + 1; j <= 40; j++) g[j - a[i]] = min(g[j - a[i]], f[j]);
if (a[i] == 10)
for (int j = 1; j <= 40; j++) g[j] = min(g[j], f[j - 1] + 10);
if (a[i] == 20)
for (int j = 2; j <= 40; j++) g[j] = min(g[j], f[j - 2] + 20);
memcpy(f, g, sizeof(g));
}
ans = 1e9;
for (int i = 0; i <= 40; i++) ans = min(ans, f[i]);
printf("%d", ans * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n, long long m = mod) {
a %= m;
long long res = 1;
while (n) {
if (n & 1) res = res * a % m;
a = a * a % m;
n >>= 1;
}
return res;
}
struct modint {
long long n;
modint() : n(0) { ; }
modint(long long m) : n(m) {
if (n >= mod)
n %= mod;
else if (n < 0)
n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
a.n += b.n;
if (a.n >= mod) a.n -= mod;
return a;
}
modint operator-=(modint &a, modint b) {
a.n -= b.n;
if (a.n < 0) a.n += mod;
return a;
}
modint operator*=(modint &a, modint b) {
a.n = ((long long)a.n * b.n) % mod;
return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0) return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2) res = res * a;
return res;
}
long long inv(long long a, long long p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b) return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int sz = 50;
int dp[sz];
int cop[sz];
void solve() {
int n;
cin >> n;
vector<int> a(n);
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] /= 100;
sum += a[i];
}
for (int i = 0; i < sz; i++) dp[i] = -mod;
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < sz; j++) cop[j] = -mod;
if (a[i] == 10) {
for (int j = 0; j < sz; j++) {
if (j + 1 < sz) {
cop[j + 1] = max(cop[j + 1], dp[j]);
}
for (int d = 1; d <= 10; d++) {
if (j - d >= 0) {
cop[j - d] = max(cop[j - d], dp[j] + d);
}
}
}
} else {
for (int j = 0; j < sz; j++) {
if (j + 2 < sz) {
cop[j + 2] = max(cop[j + 2], dp[j]);
}
for (int d = 1; d <= 20; d++) {
if (j - d >= 0) {
cop[j - d] = max(cop[j - d], dp[j] + d);
}
}
}
}
for (int j = 0; j < sz; j++) dp[j] = cop[j];
}
int ma = 0;
for (int j = 0; j < sz; j++) ma = max(ma, dp[j]);
int ans = sum - ma;
ans *= 100;
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
char nyaa;
cin >> nyaa;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
<< endl;
}
const long long int mod = 1000000007ll;
int arr[300005];
int n;
int dp[300005][41];
int func(int pos, int b) {
if (pos == n) return 0;
if (b > 40) return mod;
int& res = dp[pos][b];
if (res != -1) return res;
res = func(pos + 1, b + arr[pos] / 10) + arr[pos];
res = min(res, func(pos + 1, max(0, b - arr[pos])) + max(0, arr[pos] - b));
return res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
arr[i] /= 100;
}
memset(dp, -1, sizeof dp);
printf("%d\n", func(0, 0) * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, sum, tot, ans;
int a[400400];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i] / 1000;
tot += (a[i] == 1000);
}
int temp = sum * 10 / 11;
if (sum <= 11) temp = sum - a[n] / 1000;
if (!tot && temp % 2 == 1) temp--;
cout << sum * 1000 - temp * 100;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, x, f[3500], g[3500], ans = 1e9, maxn = 3000;
int main() {
scanf("%d", &n);
memset(f, 127, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
memcpy(g, f, sizeof(f));
memset(f, 127, sizeof(f));
scanf("%d", &x);
for (int j = 0; j <= maxn; j += 100)
f[j + x / 10] = min(f[j + x / 10], g[j] + x);
for (int j = 0; j <= maxn; j += 100)
f[j - min(j, x)] = min(f[j - min(j, x)], g[j] + max(0, x - j));
}
for (int i = 0; i <= maxn; i += 100) ans = min(ans, f[i]);
printf("%d\n", ans);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
const int M = 31;
int n;
int a[N];
int d[N][M];
int DP(int i, int bonus) {
if (d[i][bonus] != -1) return d[i][bonus];
if (i == n) return max(0, a[i] - bonus);
if (bonus > M - 1) return N * M;
return d[i][bonus] =
min(max(0, a[i] - bonus) + DP(i + 1, max(0, bonus - a[i])),
a[i] + DP(i + 1, bonus + (a[i] / 10)));
}
int main() {
scanf("%d", &n);
memset(d, -1, sizeof(d));
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
a[i] /= 100;
}
printf("%d", DP(0, 0) * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
const int INF = 1e9;
int n, a[MAXN], f[35], g[35];
int main() {
scanf("%d", &n);
for (int i = 1; i <= 31; ++i) g[i] = INF;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
a[i] /= 100;
f[0] = f[1] = INF;
for (int j = a[i] / 10; j <= 31; ++j) f[j] = g[j - a[i] / 10] + a[i];
for (int j = a[i]; j <= 31; ++j) f[j - a[i]] = min(f[j - a[i]], g[j]);
for (int j = 1; j < a[i]; ++j) f[0] = min(f[0], g[j] + a[i] - j);
for (int j = 0; j <= 31; ++j) g[j] = f[j];
}
for (int i = 1; i <= 31; ++i) g[0] = min(g[0], g[i]);
printf("%d\n", g[0] * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[300005][45], n, value[300005];
void update(int &x, int y) { x = min(x, y); }
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> value[i];
value[i] /= 100;
}
for (int i = 1; i <= n; i++)
for (int j = 0; j < 45; j++) a[i][j] = 1e9;
a[1][value[1] / 10] = value[1];
for (int i = 1; i < n; i++) {
int tmp = value[i + 1];
for (int j = 0; j < 45; j++) {
int used = min(j, tmp);
update(a[i + 1][j - used], a[i][j] + tmp - used);
update(a[i + 1][j + tmp / 10], a[i][j] + tmp);
}
}
int ans = 1e9;
for (int i = 0; i < 45; i++) ans = min(ans, a[n][i]);
cout << ans << "00" << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
const int N = 300010;
const int M = 50;
const int INF = 0x3f3f3f3f;
int dp[N][M], a[N];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
a[i] /= 100;
}
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < M; ++j) {
if (dp[i - 1][j] == INF) {
continue;
}
if (a[i] / 10 + j < M) {
dp[i][j + a[i] / 10] =
std::min(dp[i][j + a[i] / 10], dp[i - 1][j] + a[i]);
}
int x = std::min(a[i], j);
dp[i][j - x] = std::min(dp[i][j - x], dp[i - 1][j] + a[i] - x);
}
}
int min = INT_MAX;
for (int i = 0; i < M; ++i) {
min = std::min(min, dp[n][i]);
}
return printf("%d\n", min * 100), 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-9;
const long double Pi = 3.1415926535897932384626433832795;
const int N = 3e5 + 17;
const int M = 32;
int dp[N][M];
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < int(n); i++) scanf("%d", &a[i]);
for (int i = 0; i < int(N); i++)
for (int j = 0; j < int(M); j++) dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 0; i < int(n); i++) {
for (int j = 0; j < int(M); j++) {
if (j + a[i] / 1000 < M)
dp[i + 1][j + a[i] / 1000] =
min(dp[i + 1][j + a[i] / 1000], dp[i][j] + a[i]);
dp[i + 1][j - min(j, a[i] / 100)] =
min(dp[i + 1][j - min(j, a[i] / 100)],
dp[i][j] + a[i] - 100 * min(j, a[i] / 100));
}
}
int ans = INF;
for (int i = 0; i < int(M); i++) ans = min(ans, dp[n][i]);
cout << ans << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool getmin(T *a, const T &b) {
if (b < *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inline bool getmax(T *a, const T &b) {
if (b > *a) {
*a = b;
return true;
}
return false;
}
template <class T>
inline void read(T *a) {
char c;
while (isspace(c = getchar())) {
}
bool flag = 0;
if (c == '-')
flag = 1, *a = 0;
else
*a = c - 48;
while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
if (flag) *a = -*a;
}
const int mo = 40009;
template <class T>
T pow(T a, T b, int c = mo) {
T res = 1;
for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c)
if (b & i) res = 1LL * res * a % c;
return res;
}
const int N = 310000;
int f[N][35];
int a[N], n;
int main() {
cin >> n;
for (register int i = (1); i <= (n); ++i) read(a + i);
for (register int i = (0); i <= (33); ++i)
for (register int j = (0); j <= (n); ++j) f[j][i] = 1e9;
f[0][0] = 0;
for (register int i = (0); i <= (n - 1); ++i)
for (register int j = (0); j <= (33); ++j) {
int x = j * 100, y = a[i + 1] / 1000;
if (j + y <= 33) getmin(&f[i + 1][j + y], f[i][j] + a[i + 1]);
if (x >= a[i + 1]) getmin(&f[i + 1][(x - a[i + 1]) / 100], f[i][j]);
if (x < a[i + 1]) getmin(&f[i + 1][0], f[i][j] + a[i + 1] - x);
}
int ans = 1e9;
for (register int i = (0); i <= (33); ++i) getmin(&ans, f[n][i]);
cout << ans << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
const int N = 3e5 + 10;
using namespace std;
int n, A[N];
int dp[2][50];
int main() {
memset(dp, 0x3f, sizeof(dp));
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &A[i]);
A[i] /= 100;
}
int s = 0, t = 1;
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
int a = A[i] / 10;
for (int j = 0; j <= 40; ++j)
if (dp[s][j] < dp[0][49]) {
if (j + a <= 40) dp[t][j + a] = min(dp[t][j + a], dp[s][j] + A[i]);
int b = min(j, A[i]);
if (b) dp[t][j - b] = min(dp[t][j - b], dp[s][j] + A[i] - b);
dp[s][j] = dp[0][49];
}
swap(s, t);
}
int ans = dp[0][49];
for (int i = 0; i < 20; ++i) ans = min(ans, dp[s][i]);
printf("%d00\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 3e5 + 5;
const int MAXN = 1000000;
const int MAX_N = MAX;
const long long MOD = 1e9 + 7;
const long double pi = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <class T>
inline void read(T& num) {
bool start = false, neg = false;
char c;
num = 0;
while ((c = getchar()) != EOF) {
if (c == '-')
start = neg = true;
else if (c >= '0' && c <= '9') {
start = true;
num = num * 10 + c - '0';
} else if (start)
break;
}
if (neg) num = -num;
}
inline long long powMM(long long a, long long b, long long M) {
long long ret = 1;
a %= M;
while (b) {
if (b & 1) ret = ret * a % M;
b >>= 1;
a = a * a % M;
}
return ret;
}
void open() {
freopen("1009.in", "r", stdin);
freopen("out.txt", "w", stdout);
}
int n, dp[2][31], tem, now, pre, an = INF;
int main() {
scanf("%d", &n);
memset(dp, 0x3f, sizeof(dp));
now = 1;
dp[pre][0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &tem);
;
for (int j = 0; j <= 30; j++) {
dp[now][min(30, j + tem / 1000)] =
min(dp[now][min(30, j + tem / 1000)], dp[pre][j] + tem);
dp[now][j - min(j, tem / 100)] =
min(dp[now][j - min(j, tem / 100)],
dp[pre][j] + tem - min(j, tem / 100) * 100);
}
swap(now, pre);
memset(dp[now], 0x3f, sizeof(dp[now]));
}
for (int j = 0; j <= 30; j++) an = min(an, dp[pre][j]);
printf("%d\n", an);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 10;
long long dp[N][40];
int n;
long long a[N];
int main() {
memset(dp, 0x3f3f3f3f, sizeof(dp));
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a[i]);
a[i] /= 100;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int cards = a[i] / 10;
for (int j = 0; j <= 31; j++) {
if (dp[i - 1][j] < 0x3f3f3f3f) {
if (j + cards <= 31)
dp[i][j + cards] = min(dp[i][j + cards], dp[i - 1][j] + a[i]);
int b = min((long long)j, a[i]);
if (b) {
dp[i][j - b] = min(dp[i][j - b], dp[i - 1][j] + a[i] - b);
}
}
}
}
long long ans = 0x3f3f3f3f;
for (int i = 0; i < 20; i++) {
if (dp[n][i] < ans) ans = dp[n][i];
}
printf("%I64d00\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[300010];
int dp[300010][70];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
memset(dp, 0x3f3f3f3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 50; j++)
if (dp[i][j] != 0x3f3f3f3f) {
dp[i + 1][j + a[i + 1] / 1000] =
min(dp[i + 1][j + a[i + 1] / 1000], dp[i][j] + a[i + 1]);
dp[i + 1][j - min(a[i + 1] / 100, j)] =
min(dp[i + 1][j - min(a[i + 1] / 100, j)],
dp[i][j] + a[i + 1] - 100 * min(a[i + 1] / 100, j));
}
}
int ans = 0x3f3f3f3f;
for (int i = 0; i < 50; i++) {
ans = min(ans, dp[n][i]);
}
printf("%d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 5;
int add(int x, int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
int mul(int x, int y) {
long long z = 1LL * x * y;
return z - z / mod * mod;
}
int a[maxn], b[maxn];
int f[2][55];
void updata(int &x, int y) { x = max(x, y); }
int main() {
int n, i, j, u, v, s;
scanf("%d", &n);
for (i = 1, s = 0; i <= n; i++) {
scanf("%d", &a[i]);
b[i] = a[i] / 100;
a[i] /= 1000;
s += a[i];
}
u = 0;
f[0][0] = 1;
for (i = 1; i <= n; i++) {
v = u ^ 1;
memset(f[v], 0, sizeof(f[v]));
for (j = 0; j <= 50; j++) {
if (f[u][j]) {
if (j < b[i])
updata(f[v][0], f[u][j] + j);
else
updata(f[v][j - b[i]], f[u][j] + b[i]);
if (j + a[i] <= 50) updata(f[v][j + a[i]], f[u][j]);
}
}
u ^= 1;
}
int x = 1;
for (i = 0; i <= 50; i++) x = max(x, f[u][i]);
x--;
printf("%d\n", s * 1000 - x * 100);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int n, ans, sa, sb, S;
int a[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), sa += a[i] / 1000, sb += (a[i] == 1000);
S = sa * 10 / 11;
if (sa <= 11) S = sa - a[n] / 1000;
if (sb == 0 && (S & 1)) S--;
printf("%d\n", sa * 1000 - S * 100);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') ch == '-' && (f = 0) || (ch = getchar());
while (ch <= '9' && ch >= '0')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return f ? x : -x;
}
int a[300020], f[2][50];
int main(int argc, char const *argv[]) {
int n = read();
for (int i = 1; i <= n; i++) a[i] = read() / 100;
int now = 0, pre = 1;
memset(f, 63, sizeof f);
f[now][0] = 0;
for (int i = 1; i <= n; i++) {
swap(now, pre);
int x = a[i] / 10;
memset(f[now], 63, sizeof f[now]);
for (int j = 0; j < 40; j++) {
if (j + x < 40) f[now][j + x] = f[pre][j] + a[i];
int y = min(j, a[i]);
if (y) f[now][j - y] = min(f[now][j - y], f[pre][j] + a[i] - y);
}
}
int asuna = 1 << 30;
for (int i = 0; i < 30; i++) asuna = min(asuna, f[now][i]);
printf("%d00\n", asuna);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005, INF = 0x3f3f3f3f;
int dp[N][31], s[N], n;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
memset(dp, 0x3f, sizeof(dp));
cin >> n;
for (int i = 1; i <= (n); ++i) cin >> s[i], s[i] /= 100;
dp[0][0] = 0;
for (int i = 1; i <= (n); ++i) {
for (int j = 0; j < (31); ++j)
for (int k = 1; k <= (s[i]); ++k)
if (j + s[i] < 31)
dp[i][j] = min(dp[i][j], dp[i - 1][j + k] + s[i] - k);
for (int j = 0; j < (31); ++j)
if (j - s[i] / 10 >= 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j - s[i] / 10] + s[i]);
}
int ans = INF;
for (int i = 0; i < (31); ++i) ans = min(ans, dp[n][i]);
cout << ans * 100 << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 99, M = 45, inf = 1e9;
int n, t, a[N], dp[N][M], ans = inf;
int main() {
cin >> n;
for (int i = 1; i < n + 1; i++) {
cin >> a[i];
a[i] /= 1000;
}
for (int i = 1; i < M; i++) dp[0][i] = inf;
for (int i = 1; i < n + 1; i++)
for (int j = 0; j < M; j++) {
dp[i][j] = inf;
if (j >= a[i]) dp[i][j] = dp[i - 1][j - a[i]] + a[i] * 10;
for (int l = j + 1; l < M; l++)
dp[i][j] = min(dp[i][j], dp[i - 1][l] + max(a[i] * 10 - (l - j), 0));
;
}
for (int i = 0; i < M; i++) ans = min(ans, dp[n][i]);
;
cout << ans * 100ll;
}
| 10 | CPP |