nilsilu95's blog

By nilsilu95, history, 9 years ago, In English

why my code gives warning "Please do not use the %lld (or similar) specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. Press button to submit the solution."

and also gives wa for n=10**9?My code in my computer gives ans as 8888888899 but in site, it is 8888888898?

#include <bits/stdc++.h>  
using namespace std;  
#define lli long long int
const int MAX=1e9+7;
lli solve(lli n){
	lli sz=log10(n)+1;
	if(sz==1)return n;
	lli ans=9+(n-pow(10,sz-1)+1)*sz;
	for(int i=sz-1;i>1;i--){
		ans+=9*i*pow(10,i-1);
	}
	return ans;
}
int main()  
{  
  
		lli n;
		cin>>n;
    	cout<<solve(n)<<"\n";
  	return 0;  
}  
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

as mentioned previously, pow() function returns double so it's probably double precision error this is somehow fix for this issue don't depend on it for all cases