BRTNUM - Editorial

PROBLEM LINK:

Practice
Contest

Author: Vikas Yadav
Tester: Lalit
Editorialist: Vikas Yadav

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Operator

PROBLEM:

Check whether 1729 is present in the given integer or not.

QUICK EXPLANATION:

Check 1729 in the given Integer using arithmetic operator (% and /) .

EXPLANATION:

First we take input the number of test cases as integer. Then for each test case we have to take a number (long long int) as input and to check whether 1729 is present in that number or not.
1729 is 4 digit number, so we take remainder of given number with 10000 using modulo operator. If then result is 1729 then print “Yes” and break the loop. Otherwise we divide the number by 10 to remove last digit and repeat the previous step until the number is less than 1000. If we did not find the 1729 in the given number then print “No”.
Do this for all the test cases.
For more details check Setter’s Solution.

ALTERNATE EXPLANATION:

In case of Python language we can take the input as string and check whether “1729” is present in the siring or not.
For more details check Tester’s Solution.

SOLUTIONS:

Setter's Solution
#include <stdio.h>

int main() 
{
	int test;
	scanf("%d", &test);

	while(test--)
	{
		long long num;
		scanf("%lld", &num);

		int ramanujan_num = 1729, flag = 0;

		while(num > 1000)
		{
			int remainder = num % 10000;
			if(remainder == ramanujan_num)
			{
				flag = 1;
				break;
			}
			num /= 10;
		}

		printf(flag ? "Yes\n" : "No\n");
	}

	return 0;
}
Tester's Solution
test = int(input())

while test:
	test -= 1
	number = input()

	if '1729' in number:
		ans  ='Yes'
	else:
		ans = 'No'
print(ans)