You are given two integers n and m (m
Your task is to say if it is possible to build another convex regular polygon with m vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.
You have to answer t independent test cases.
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
The next t lines describe test cases. Each test case is given as two space-separated integers n and m (3≤m
For each test case, print the answer — “YES” (without quotes), if it is possible to build another convex regular polygon with m vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and “NO” otherwise.
2
6 3
7 3
YES
NO
#include
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(n%m==0){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}
You are given an array a1,a2,…,an. Array is good if for each pair of indexes i
It’s guaranteed that it’s always possible to shuffle an array to meet this condition.
The first line contains one integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤100) — the length of array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤100).
For each test case print the shuffled version of the array a which is good.
3
1
7
4
1 1 3 5
6
3 2 1 5 6 4
7
1 5 1 3
2 4 6 1 3 5
#include
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
bool cmp(int x, int y)
{
return x > y;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int s[110];
for(int i = 1; i <= n; i++) cin >> s[i];
if(n==1){
cout << s[1] << endl;
}else{
sort(s+1,s+n+1,cmp);
for(int i = 1; i <= n; i++) cout << s[i] << " ";
cout << endl;
}
}
return 0;
}
Suppose you are performing the following algorithm. There is an array v1,v2,…,vn filled with zeroes at start. The following operation is applied to the array several times — at i-th step (0-indexed) you can:
either choose position pos (1≤pos≤n) and increase vpos by ki;
or not choose any position and skip this step.
You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array v equal to the given array a (vj=aj for each j) after some step?
The first line contains one integer T (1≤T≤1000) — the number of test cases. Next 2T lines contain test cases — two lines per test case.
The first line of each test case contains two integers n and k (1≤n≤30, 2≤k≤100) — the size of arrays v and a and value k used in the algorithm.
The second line contains n integers a1,a2,…,an (0≤ai≤1016) — the array you’d like to achieve.
For each test case print YES (case insensitive) if you can achieve the array a after some step or NO (case insensitive) otherwise.
5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810
YES
YES
NO
NO
YES
#include
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin >> t;
while(t--){
ull n, k;
cin >> n >> k;
ull s[100];
for(int i = 0; i < n; i++) cin >> s[i];
sort(s,s+n);
int flag = 1;
ull cnt = 0;
ull maxn = s[n-1];
ull x = 1;
while(x<=maxn){
cnt++;
x = pow(k,cnt);
}
ull q[100];
mem(q);
for(int i = 0; i < n; i++){
if(s[i]!=0){
ull y = s[i];
for(int j = cnt-1; j >= 0; j--){
ull z = pow(k,j);
if(y>=z) y -= z;
}
if(y==0){
y = s[i];
for(int j = cnt-1; j >= 0; j--){
ull z = pow(k,j);
if(y>=z){
y -= z;
q[j]++;
}
}
}else{
flag = 0;
break;
}
}
}
for(int i = 0; i < cnt; i++){
if(q[i]>1){
flag = 0;
break;
}
}
if(flag==1){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}
return 0;
}