Skip to content

Instantly share code, notes, and snippets.

@hoanbka
Created December 2, 2017 18:17
Show Gist options
  • Save hoanbka/e3ccb67c093405cd39ee818ab8cff9d5 to your computer and use it in GitHub Desktop.
Save hoanbka/e3ccb67c093405cd39ee818ab8cff9d5 to your computer and use it in GitHub Desktop.
Chtholly's request
#include <bits/stdc++.h>
using namespace std;
string tostr(int n) {
stringstream s;
string x;
while (n > 0) {
x += (n % 10 + '0');
n /= 10;
}
reverse(x.begin(), x.end());
return x;
}
int main() {
string x, y;
int p, k;
cin >> k >> p;
int a = 1;
long long ans = 0;
while (k--) {
x = tostr(a++);
y = x;
reverse(x.begin(), x.end());
y += x;
unsigned long long sum = 0;
reverse(y.begin(), y.end());
for (int i = 0; i < y.size(); i++) {
sum = (sum * 10) + (y[i] - '0');
}
ans = (ans + sum) % p;
ans %= p;
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment