CONN - EDITORIAL

PROBLEM LINK:

Contest
Practice

Setter: soumyadeep_21(abhi_inav | CodeChef User Profile for Abhinav Gupta | CodeChef)
Testers: inov_360, mexomerf
Editorialist: hrishik85

DIFFICULTY:

860

PREREQUISITES:

None

PROBLEM:

Given an integer N, we have to output if

  • N can be represented as N = 2 \times X + 7 \times Y
  • where X, Y \geq 0

EXPLANATION:

If you write out an example sequence of numbers [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] you realise that the only numbers which cannot be represented in the format required are [1, 3, 5].
For N \geq 7, all numbers can be represented in the format above.

TIME COMPLEXITY:

Time complexity is O(1).

SOLUTION:

Editorialist's Solution
t=int(input())
for _ in range(t):
    N=int(input())
    if N>=7:
        print('YES')
    else:
        if N%2==0:
            print('YES')
        else:
            print('NO')
1 Like

x and y can be float?

@sameergoyal125 - the problem states that X and Y are integers.

I recently went through the solution for this and the logic prints β€œYES” for all numbers greater than 7. now if we give 101 as a test case, its not possible to represent it using 7 and 2’s combinations. can someone clarify it???

1 Like

@rohanpadile - 101 = 13 * 7 + 5 * 2 = 1 * 7 + 47 * 2

1 Like