代码
#include <iostream>
using namespace std;
int main(){
int x=1e9,y=1e9;
const int N=1e9+1;
cout<<1ll*y*(1e9+1)+x<<'\n';
cout<<1ll*y*(1000000001)+x<<'\n';
cout<<1ll*y*N+x<<'\n';
cout<<1ll*y*(int)(1e9+1)+x<<'\n';
return 0;
}
结果
1e+18
1000000002000000000
1000000002000000000
1000000002000000000
分析
可以发现,第一行是错的,因为double丢失精度了
一定注意1e9是double型,如果要当int,需要提前转化成int型
题号??