Codeforces not showing correct output.

I am doing this question on codeforces.

It shows wrong answer on test case 12, it says correct answer is 674074074074073.
but on my terminal it shows 674074074074073 answer only.

What could be the reason ?

Here is my code.

typedef long long ll;
using namespace std;

int count(ll m)
{
    int cnt = 0;

    while(m!=0)
    {
        cnt++;
        m /= 10;
    }
return cnt;
}

int main()
{

    ll w,m,k;

    cin >> w >> m >> k;

    ll ans = 0;
    int dig = count(m);
    
    while(1)
    {
        ll num = pow(10,dig);
        
        if(w >= ((num-m)*dig*k))
        {
            ans += (num-m);
            w = w-((num-m)*dig*k);
            m = num;
        }
        else
        {
            ans += (w/(k*dig));
            break;
        }
        dig++;
    }
    cout << ans << endl;
    
return 0;
}

alt text

No, your output is coming 674074074074072 not 674074074074073 . Please check the screenshot of your submission on codeforces.

In your code, there is overflow problem, use unsigned long long instead of long long . Also, do not use inbuilt pow function for calculating pow(10,dig), make your own code for calculating it. Since, sometimes the pow function gives wrong answer in c/c++. e.g. in my codeblocks, it is showing pow(10,2)=99. So, please write your own code for it. Best of luck!!

2 Likes

Yes, pow function is the reason, thanks a lot… :slight_smile: