Sherlock and The Beast

  • + 2 comments

    No need for repeated subtractions or loops. It's purely O(1) (just straightforward formula split in two parts, two calculations).

    int q = ((3-(N%3))%3) *5;
    if (N-q < 0)
    	cout << -1 << endl;
    else
    	cout << string(N-q,'5') << string(q,'3') << endl;