Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD
DIFFICULTY:
CAKEWALK, SIMPLE, EASY.
PREREQUISITES:
Math .
PROBLEM:
Chahal is very intelligent boy , he always play chess there for he has sharp mind but now his father is given a challange to him he is given a series and he has to find Nth term in the series.
1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, 64 . . .
QUICK EXPLANATION:
you have simply given a series of number in that you have to find a given term in the series
that is if you have given a n=3 then the nth term will be 2 like this you have to find it .
EXPLANATION:
you have simply given a series of number in that you have to find a given term in the series
that is if you have given a n=3 then the nth term will be 2 like this you have to find it .
in given series except first two number others are multiple of 3 and 2 alternatively you have just multiply the given number by 3 and 2 and find the nth term .
SOLUTIONS:
Setter's Solution
//chahal and mind game
#include <bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n, a, b;
cin >> n;
for (long long int i = 1; i <= n; i++)
{
if (i % 2 != 0)
{
if (i == 1)
{
a = 1;
}
else
{
a = a * 2;
}
}
else
{
if (i == 2)
{
b = 1;
}
else
{
b = b * 3;
}
}
}
if (n % 2 != 0)
{
cout << a;
}
else
{
cout << b;
}
}
int main()
{
int t;
cin >> t;
while (t–)
{
testcase();
cout << endl;
}
return 0;
}
Tester's Solution
//chahal and mind game
#include <bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n, a, b;
cin >> n;
for (long long int i = 1; i <= n; i++)
{
if (i % 2 != 0)
{
if (i == 1)
{
a = 1;
}
else
{
a = a * 2;
}
}
else
{
if (i == 2)
{
b = 1;
}
else
{
b = b * 3;
}
}
}
if (n % 2 != 0)
{
cout << a;
}
else
{
cout << b;
}
}
int main()
{
int t;
cin >> t;
while (t–)
{
testcase();
cout << endl;
}
return 0;
}
Editorialist's Solution
//chahal and mind game
#include <bits/stdc++.h>
using namespace std;
void testcase()
{
long long int n, a, b;
cin >> n;
for (long long int i = 1; i <= n; i++)
{
if (i % 2 != 0)
{
if (i == 1)
{
a = 1;
}
else
{
a = a * 2;
}
}
else
{
if (i == 2)
{
b = 1;
}
else
{
b = b * 3;
}
}
}
if (n % 2 != 0)
{
cout << a;
}
else
{
cout << b;
}
}
int main()
{
int t;
cin >> t;
while (t–)
{
testcase();
cout << endl;
}
return 0;
}