We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- All Contests
- HourRank 16
- Lucky Numbers
- Discussions
Lucky Numbers
Lucky Numbers
Sort by
recency
|
29 Discussions
|
Please Login in order to post a comment
Quite easy using recursion: import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}
Use modulus. Psudo code: if n % 4, 7, 11 != 0: print("No") else: print("yes")
what's the issue with this code :
We have
7(x-4)+4(y+7)=7x+4y
So if (x, y) is a solution, then (x-4,y+7) is also a solution. Hence if there is a solution then there is one with x<4. That's why you only need to test x=0..3 which runs in constant time.
This can be extended to any equation of the form ax+by=n, you only need to test x=0..b-1.