1651B - Prove Him Wrong - CodeForces Solution


constructive algorithms greedy

Please click on ads to support us..

Python Code:

for i in range(int(input())):
	a = int(input())
	if a>19:
		print("NO")
	else:
		print("YES")
		print(*[3**i for i in range(a)])

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define read(x) {x=0;char z;while((z=getchar())<48);do x=x*10+(z^48);while((z=getchar())>47);}
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10;
const int mod=80112002;
vector<LL> a(100);
void solve()
{
	LL n;cin >> n;
	if(n>19)
	{
		cout << "NO\n";return;
	}
	cout << "YES\n";
	for(int i=1;i<=n;i++)cout << a[i] << " \n"[i==n];
	
	
}
int main()
{
	int tc;cin >> tc;a[1]=1;
	for(int i=2;i<=25;i++)a[i]=a[i-1]*3;
	while(tc--)
	{
		solve();
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme