Skip to content

Commit

Permalink
multof2019
Browse files Browse the repository at this point in the history
  • Loading branch information
megargayu committed Oct 12, 2022
1 parent be2b777 commit 368e4d4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions other/multof2019/multof2019.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 200000
#define ll long long

vector<int> cnt(2019, 0);

int main()
{
string s;
cin >> s;

int num = 0, power = 1;
cnt[0] = 1;
for (int i = s.size() - 1; i >= 0; --i)
{
num = (num + power * (s[i] - '0')) % 2019;
++cnt[num];
power = (power * 10) % 2019;
}

ll ans = 0;
for (int i = 0; i < 2019; ++i)
ans += static_cast<ll>(cnt[i]) * (cnt[i] - 1) / 2;

cout << ans << '\n';

return 0;
}

0 comments on commit 368e4d4

Please sign in to comment.