why this program is not working?

why this program is not working?

And Is it’s logic correct?

question : https://www.codechef.com/problems/PPNUM/

My soln https://ideone.com/LhnETw why its not working.

Recheck line number 11, pref[0] value is not defined!

ll x= pref[i-1]+(int)(log10(i)+1)*i;

You have taken l and r as long long int and scanning them as int. Also pref is an int vector and you are printing the answer as long long int.


1 ≤ L ≤ R ≤ 1,000,000,000 (10^9)

For these contraints you will surely exceed memory/time limit for current logic.

So try another approach,

From contraints you can observe the number of digits say d would follow as,

1 ≤ d ≤ 10

So, find sum of no.s having same no. of digits using Arithmetic Progression and multiply it by no. of digits.

You’ll need to do it for 10 segments(Worst case)

Worst Case Complexity: O(10) per test case

You can futher reduce this using prefix sum array.

1 Like

please help me fast

no,then also it’s not working

@idiot_owl , now also it’s not working.

You cannot have a loop till 109.

so what should i do in place of it?


pref[0]=0; is where you are wrong.

pref.push_back(0); is the correct way.