3 and 7 in Python
Suppose we have a positive number n, we have to find that we can make n by summing up some non-negative multiple of 3 and some non-negative multiple of 7 or not.
So, if the input is like 13, then the output will be True, as 13 can be written as 1*7+2*3 = 13
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
Example
Live Demo
class Solution:
def solve(self, n):
for i in range(0,n+1,7):
if (n-i)%3 == 0:
return True
return False
ob = Solution()
print(ob.solve(13))
Input
13
Output
True
Published on 02-Sep-2020 12:36:38
- Related Questions & Answers
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + + (1+3+5+7+....+(2n-1)) in C++
- Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + ...... + (1+3+5+7+...+(2n-1)) in C++
- Multiples of 3 or 7 in C++
- Finding n-th number made of prime digits (2, 3, 5 and 7) only in C++
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- Exceptions and Error in PHP 7
- Understanding Code Reuse and Modularity in Python 3
- Find sum of the series 1-2+3-4+5-6+7....in C++
- Differences between Python 2.x and Python 3.x?
- 3-6-9 in Python
- Display array structure and values in PHP 7
- Why MySQL uses the interval like 7 day and 2 hour instead of 7 days and 2 hours?
- Base 3 to integer in Python
- Preg_replace_callback_array() in PHP 7
- Replace Multiple of 3 and 5 With Fizz, Buzz in Python