Caramelio's blog

By Caramelio, 5 years ago, In English

Matryoshka Dolls This is the problem I am stuck on. I wrote the source code in C++, which is down below. It failed on the 2nd test.

#include<iostream>
using namespace std;

int main(){
    int s, x;
    cin >> s >> x;
    cout << (s-x)/x << endl;
}

If you have some time to spare, please help me. Thank you!!

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

As mentioned, the idea is so simple. The statement of problem clearly says what you need to do. Initially you have size S, next one should be S/X according to the statement, Then the next one is (S/X)/X, So what you need to calculate is logarithm S to the base X. This can be done using while loop.

Code