#include<bits/stdc++.h>
#define ull unsigned long long
#define int128 unsigned __int128
using namespace std;
int128 mod = ((int128)1<<64) - 6777;
int main()
{ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string A,B,C;
cin>>A>>B>>C;
const int n=(int)A.size();
long long wynik=0;
unordered_map<ull,int>M;
M[0]++;
int128 poww=1,hasz=0;
for(int i=n-1;i>=0;i--)
{
int128 u = A[i]+B[i]-C[i]-'0';
u=(u+mod)%mod;
hasz=(hasz+poww*u)%mod;
poww=(poww*10)%mod;
wynik+=M[hasz];
M[hasz]++;
}
cout<<wynik<<'\n';
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<bits/stdc++.h> #define ull unsigned long long #define int128 unsigned __int128 using namespace std; int128 mod = ((int128)1<<64) - 6777; int main() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); string A,B,C; cin>>A>>B>>C; const int n=(int)A.size(); long long wynik=0; unordered_map<ull,int>M; M[0]++; int128 poww=1,hasz=0; for(int i=n-1;i>=0;i--) { int128 u = A[i]+B[i]-C[i]-'0'; u=(u+mod)%mod; hasz=(hasz+poww*u)%mod; poww=(poww*10)%mod; wynik+=M[hasz]; M[hasz]++; } cout<<wynik<<'\n'; return 0; } |
English