B. Ordinary Numbers

problem link : https://codeforces.com/problemset/problem/1520/B

I understood the problem and i known the logic still program is giving wrong answer.

#include

using namespace std;

using ll = long long;

int main()

{

ll t;

cin>>t;

while(t--)

{

    ll n;

    cin>>n;

    ll count=0;

        for(ll i=1;i<=n;i++)

        {

            ll temp = i;

            while(temp<=n)

            {   

                temp = (temp*10)+i;

                count++;

                

            }

            

        }

        cout<<count<<"\n";

    

}

}

Try this testcase
1
11
Your output-12
Correct output -11

you are getting wrong answer because you running loop till n
and some value of n is recount
try loop from 1 to 9

1 Like

Here is one of my approaches to solving this question.

Link to Code

Thanks Bro . It’s worked

I understood my mistake but still can you explain ur logic so i learn something new