C++
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
unsigned long long int t,n,i,m,su,s,k;
int main()
{
cin>>n;
if(n==0)
{
cout<<"0\n";
return 0;
}
m = sqrt(n);
su = m*(m+1)/2;
s = n-1;
for(i=2;i*i<=n;i++)
{
k = n/i;
s = s + (k-1)*i + k*(k+1)/2 - su;
}
cout<<s<<"\n";
}
Python
import math
n = int(input())
if n==0:
print('0')
else:
m = int(math.sqrt(n))
su = int(m*(m+1)/2)
s = n-1
i=2
while i*i<=n:
k = int(n/i)
s = s + ((k-1)*i) + int(k*(k+1)/2) - su
i = i+1
print(s)
answer coming different for 1000000000
for c++ code output = 322467033612360628
for python code output = 322467033612360629
why are the answers different?
I don't think it is caused by overflow in c++ integer because in a 64 bit environment range of unsigned long long int is 18,446,744,073,709,551,615
Edit :removed the variable t it was creating confusion
322467033612360628which matches your c++ output.s = 125000001750008744 + ((333333333-1)*3) + int(333333333*(333333333+1)/2) - 499991253yields different results in python2 and python3.