Advertisement
a53

secvDiv

a53
Apr 30th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. unordered_map<long long,int> w;
  4. long long res,p=1,nr,n,L;
  5. string s;
  6. int main()
  7. {
  8. ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  9. cin>>s>>n;
  10. L=s.size()-1;
  11. w[0]=1;
  12. for(int i=L;i>=0;--i)
  13. nr=(nr+p*(s[i]-'0'))%n,p=(p*10)%n,res+=w[nr],++w[nr];
  14. cout<<res<<'\n';
  15. return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement