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 ispalindrome 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, .

回文数系列题目(经典算法):  http://blog.csdn.net/computer_liuyun/article/details/27967963

【题意】:求前k个偶数位回文数之和%p的值。

【分析】:POJ 1150/2402/3247同类题目。直接写个判断偶数位回文数的函数,将整数n逆转,逆转的方法就是利用求余%和/的思想,此题总有一个常错的地方,就是m的平方和立方可能会超范围所以一定要用long long 或者_int64即可。或者用字符串表示,可能更加通俗易懂。

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n,m,sum;
ll a[];
ll huiwen(ll n)//倒过来和的数与原来相等,那么就是回文数
{
ll ans=n,t=n;//ll ans=n 若不分偶数位,则为ans=0;
while(t)
{
ans=ans*+t%;
t/=;
}
return ans;
} int main()
{
cin>>n>>m;
for(ll i=;i<=n;i++)
{
sum=(sum+huiwen(i))%m;
}
printf("%lld\n",sum%m);
}

数字规律

#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
cin.tie();\
cout.tie();
using namespace std;
const int maxn = 1e5+;
typedef long long LL;
typedef pair<int,int> P;
LL k,p; LL getnow(LL n)
{
char str[] = {};
sprintf(str,"%lld",n);
int len = strlen(str);
for(int i=len;i<len+len;i++)
str[i] = str[*len-i-];
LL cnt = ;
sscanf(str,"%lld",&cnt);
return cnt;
} void solve()
{
LL ans = ;
for(int i=;i<=k;i++)
ans = (ans+getnow(i)) % p;
// cout<<getnow(k)<<endl;
cout<<ans<<endl;
} int main()
{
// IO;
cin>>k>>p;
solve();
return ;
}

字符串

最新文章

  1. [转]position:relative leaves an empty space
  2. android xml文件
  3. Pyhon之类学习1
  4. codeforces 613A. Peter and Snow Blower
  5. c#实现microsoft账号登入授权(OAuth 2.0)并获取个人信息
  6. SORT函数的使用方法(转载)
  7. [转]python json.dumps 中的ensure_ascii 参数引起的中文编码
  8. IDE-Ecplise-代码注释 模版 编码规范 配色
  9. 2015 多校联赛 ——HDU5316(线段树)
  10. SCOI2019 退役记
  11. [武汉集训] Cliquers
  12. jmeter java requst请求
  13. python 反射 hasattr getattr
  14. codeforces 1106 E
  15. js 递归
  16. 前端js 省市联动
  17. Is it possible to display icons in a PopupMenu?
  18. 【洛谷P1892】团伙
  19. 让QQ好友现形
  20. 网络I/O模型--02阻塞模式(多线程)

热门文章

  1. [BZOJ1597][Usaco2008 Mar]土地购买(斜率优化)
  2. Android引导页过多导致OOM内存泄漏
  3. vba通过函数调用Winrar压缩软件压缩文件
  4. 使用tensorflow设计的网络模型看不到数据流向怎么办
  5. java以正确的方式停止线程
  6. leetcode 【 Pascal&#39;s Triangle 】python 实现
  7. [python][django学习篇][6]操作数据库
  8. 学习RMQ-ST表
  9. windows部分快捷键及terminal命令
  10. 个人环境搭建——版本控制SVN