click below for solution

Monday, 31 January 2022

Div 7 Solution|Educational Codeforces round 122(Rated for div 3)

                                                                  A. Div. 7

time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

You are given an integer n. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by 7.

If there are multiple ways to do it, print any of them. If the given number is already divisible by 7, leave it unchanged.

Input

The first line contains one integer t (1t990) — the number of test cases.

Then the test cases follow, each test case consists of one line containing one integer n (10n999).

Output

For each test case, print one integer without any leading zeroes — the result of your changes (i. e. the integer that is divisible by 7 and can be obtained by changing the minimum possible number of digits in n).

If there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by 7, just print it.


Note

In the first test case of the example, 42 is already divisible by 7, so there's no need to change it.

In the second test case of the example, there are multiple answers — 2821 or 63.

In the third test case of the example, other possible answers are 357371 and 378. Note that you cannot print 077 or 77.

Solution:

solution link 1

https://shareus.in/?i=GZatxNl0g

if 1st link is not work then click on another link

Solution link 2

https://shrinke.me/0joa

Solution link 3

https://afly.pro/4dPM5oi

Solution link 4

https://afly.pro/X6gV2u4

How to get link tutorial video link

https://youtu.be/0TSsPHhgwb4



  

No comments:

Post a Comment