897BChtholly's request

来源:互联网 发布:淘宝美工设计培训 编辑:程序博客网 时间:2024/06/06 02:06

题意:求解n个回文数的和然后对%m取余。
题解:数学规律,昨晚做的时候我没找出来,一直想构造预处理,写了很多,也不对。今天看了一些博客大佬,有的用规律,有的dfs搜索,当然也有构造预处理的,肯定规律最简单咯。


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 and1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321is 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, .

#include<bits/stdc++.h>using namespace std;const int N=1e5+10;long long a[N];long long huiwen(int n){    long long ans=n,t=n;    while(t)    {        ans=ans*10+t%10;        t/=10;    }    return ans;}int main(){    int n,m;    long long sum;    while(cin>>n>>m)    {        sum=0;        for(int i=1; i<=n; i++)            sum=(sum+huiwen(i));        cout<<sum%m<<endl;    }}



原创粉丝点击