Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 −
-
for i in range 0 to n+1, increase by 7, do
-
if n-i is divisible by 3, then
return True
-
return False
Let us see the following implementation to get better understanding −
Example
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
Advertisements
