首页 > 其他分享 >Codeforces897B-Chtholly's request

Codeforces897B-Chtholly's request

时间:2022-11-22 20:03:00浏览次数:47  
标签:Chtholly int ll Codeforces897B request ans output include zcy


B. Chtholly's request

time limit per test

memory limit per test

input

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:

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

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

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

11, and the second smallest zcy number is 22.

In the second example, 

Codeforces897B-Chtholly

.

题解:i从1到k模拟,求出每一个回文数,再相加即为ans。

Code:

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#define ll long long
using namespace std;
int a[100005],t;
int Palindrome(int n)
{
for(t=1;n;t++)
{
a[t]=n%10;
n/=10;
}
t--;
int ans=0;
for(int j=1;j<=t;j++)
ans=ans*10+a[j];
return ans;
}
ll power(int t)
{
ll ans=1;
for(int i=1;i<=t;i++)ans*=10;
return ans;
}
int main()
{
int k,p;ll ans=0;
scanf("%d%d",&k,&p);
for(ll i=1;i<=k;i++)
ans=(ans+Palindrome(i)+i*power(t))%p;
printf("%I64d",ans);
return 0;
}


标签:Chtholly,int,ll,Codeforces897B,request,ans,output,include,zcy
From: https://blog.51cto.com/u_15888102/5878415

相关文章