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.
If the number(say 66317) is not divisible by 3, it will leave a modulo of either 0,1 or 2. If I decrease the number by 5, I am basically making it a multiple of 3, and the remaning digits will be a multiple of 5 as I am subtracting it from the number.
modulo 0 implies number divisibile
modulo 1 implies 5 needs to be subtracted twice.
modulo 2 implies 5 needs to be subtracted once.
Correct me if I am wrong. Completed all the test cases in 0-0.01s
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
You can solve this easily using a bit of math:
y=int(raw_input()) z=y while(z%3!=0): z-=5 if(z<0): print '-1' else:
print z*'5'+(y-z)*'3'
If the number(say 66317) is not divisible by 3, it will leave a modulo of either 0,1 or 2. If I decrease the number by 5, I am basically making it a multiple of 3, and the remaning digits will be a multiple of 5 as I am subtracting it from the number.
modulo 0 implies number divisibile modulo 1 implies 5 needs to be subtracted twice. modulo 2 implies 5 needs to be subtracted once.
Correct me if I am wrong. Completed all the test cases in 0-0.01s