#include <iostream>
using namespace std;
typedef __int128_t i128;
typedef long long ll;
int main() {
i128 ans = (i128)1<<100;
ll mod = 1e18, x = ans%mod, y = ans/mod;
if (y) printf("%lld%018lld\n",y,abs(x));
else printf("%lld\n", x);
}
若只涉及相加操作, 并且每次相加的绝对值不超过1e18, 可以避免使用int128
#include <iostream>
using namespace std;
typedef __int128_t i128;
typedef long long ll;
int main() {
ll mod = 1e18, x = 0, y = 0;
for (int i=1; i<=100000; ++i) {
x += 1ll<<50;
if (x>=mod) x-=mod,++y;
if (x<=-mod) x+=mod,--y;
}
if (y) printf("%lld%018lld\n",y,x);
else printf("%lld\n",x);
}