UVa 701 - The Archeologists' Dilemma Solution

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int n;
    while(cin>>n){
        double x=log2(n),y=log2(n+1),c=log2(10);
        int N=log10(n)+2;
        while(1){
            if(round(y+c*N-0.5)==round(x+c*N+0.5)){
                cout<<int(floor(y+c*N))<<endl;
                break;
            }
            else
                N++;
        }
    }
}

Comments