codeforces897b

好久没写博客了,一方面是没刷什么题,一方面是水。总的来说还是因为没刷题导致很水。从今天开始认认真真搞acm,立长志,而非常立志。不说了,上题吧。

cf897b

B. Chtholly's request
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
— Thanks a lot for today.

— I experienced so many great things.

— You gave me memories like dreams... But I have to leave now...

— One last request, can you...

— Help me solve a Codeforces problem?

— ......

— What?

Chtholly has been thinking about a problem for days:

If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples
input
2 100
output
33
input
5 30
output
15
Note

In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.

In the second example, .

题意:给一个k一个p,求第1个到第n个的偶数回文数字之和模p;

自己推不出偶数回文字符串的递推函数,懵逼,看人家题解才知道分开求不同位数的偶数回文数字可以完成预处理,然后暴力取模。

题目简单,主要是这个本方法受到了一点启发,不一定非要一次性考虑整个问题。。。水的话本方法还是可以的。

下面是ac代码:

#include<iostream>
#include<map>
#include<algorithm>
#include<string>
#include<cstdio>
#include<vector>
#include<functional>
#include<set>
#include<string>
#define ll long long
using namespace std;
int main()
{
ll a[100005];
int index=1;
int c,b;
for(int i=1;i<=9;i++)
a[index++]=10*i+i;
for(int i=1;i<=9;i++)
for(int j=0;j<=9;j++)
a[index++]=1000*i+100*j+10*j+i;
for(int i=1;i<=9;i++)
for(int j=0;j<=9;j++)
for(int k=0;k<=9;k++)
a[index++]=100000*i+10000*j+1000*k+100*k+10*j+i;
for(int i=1;i<=9;i++)
for(int j=0;j<=9;j++)
for(int k=0;k<=9;k++)
for(int x=0;x<=9;x++)
a[index++]=10000000*i+1000000*j+100000*k+10000*x+1000*x+100*k+10*j+i;
for(int i=1;i<=9;i++)
for(int j=0;j<=9;j++)
for(int k=0;k<=9;k++)
for(int x=0;x<=9;x++)
for(int y=0;y<=9;y++)
a[index++]=1000000000*i+100000000*j+10000000*k+1000000*x+100000*y+10000*y+1000*x+100*k+10*j+i;
a[index]= 1000000000001;
cin>>c>>b;
ll sum=0;
for(int i=1;i<=c;i++)
sum=(a[i]%b+sum%b)%b;
cout<<sum<<endl;
return 0;
}

posted @ 2017-12-05 19:49  DNoSay  阅读(224)  评论(0编辑  收藏  举报