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.
Sherlock and The Beast
Sherlock and The Beast
+ 0 comments Here is my c++ solution, you can have the implementation link here : https://youtu.be/R01NQ4Zt2qA
void decentNumber(int n) { int three = ((3 - (n % 3)) % 3 ) * 5; if(three > n) cout << -1; else cout << string(n - three, '5') << string(three, '3'); cout << endl; }
+ 0 comments Py 3
def decentNumber(n): if n in [1,2,4,7]: print(-1) elif n % 3 == 0: print('5'*n) elif n%5 == 0 and (n-5) % 3 != 0 and (n-10) % 3 != 0: print('3'*n) elif (n-5) % 3 == 0: print('5'*(n-5) + '3'*5) elif (n-10) % 3 == 0: print('5'*(n-10) + '3'*10)
+ 0 comments My new Python 3 Solution:
def decentNumber(n): if n in (1,2,4,7): print(-1); return threes = (0, 10, 5)[n%3] print('5'*(n-threes)+'3'*threes)
+ 0 comments def decentNumber(n): if n in [1, 2, 4, 7]: print('-1') else: i = 0 while n % 3 != 0: n -= 5 i += 5 print('5' * n + '3' * i)
+ 0 comments C++ code solution
void decentNumber(int n) { if (n == 1){cout << "-1" << endl; return;} long number5 = 0, number3 = 0; bool flag = false; for (int i = n; i >= 0; i--){ if (i % 3 == 0 && (n-i) % 5 == 0){ number3 = n-i; number5 = i; flag = true; break; } } if (flag == false){cout << "-1" << endl;return;} for (long i = 0; i < number5; i++)cout << "5"; for (long i = 0; i < number3; i++)cout << "3"; cout << endl; }
Load more conversations
Sort 513 Discussions, By:
Please Login in order to post a comment