todi_kunal's blog

By todi_kunal, history, 7 years ago, In English

Question is 817C

Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than n.

Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.

Constraints: 1<s,n<10^18

The solution given is O(logn) but i was trying O(1) and my solution ran for test cases.Can someone suggest some modification in it that it becomes valid.

int main() {

LL n,s;
cin>>n>>s;
if(s%9)
{
    LL x=(s-s%9+9);
    LL y=(x-x%10+10)-1;
    if(n-y<=0)
    cout<<0;
    else
    cout<<n-y;
}
else
{
    LL x=(s-s%9);
    LL y=(x-x%10+10)-1;
    if(n-y<=0)
    cout<<0;
    else
    cout<<n-y;
}
// your code goes here
return 0;

}

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

| Write comment?