- 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++
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++
- Understanding Code Reuse and Modularity in Python 3
- Differences between Python 2.x and Python 3.x?
- Exceptions and Error in PHP 7
- 3-6-9 in Python
- Display array structure and values in PHP 7
- Important differences between Python 2.x and Python 3.x with examples
- Base 3 to integer in Python
- Replace Multiple of 3 and 5 With Fizz, Buzz in Python
- Why MySQL uses the interval like 7 day and 2 hour instead of 7 days and 2 hours?
- What are the differences in between python 2.x and python 3.x versions?
- What are the key differences between Python 2.7.x and Python 3.x?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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 −

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))

13

True

Advertisements