Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- unordered_map<long long,int> w;
- long long res,p=1,nr,n,L;
- string s;
- int main()
- {
- ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- cin>>s>>n;
- L=s.size()-1;
- w[0]=1;
- for(int i=L;i>=0;--i)
- nr=(nr+p*(s[i]-'0'))%n,p=(p*10)%n,res+=w[nr],++w[nr];
- cout<<res<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement