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 //B.Chtholly's request 处理前一半
2 #include<iostream>
3 #include<cstdlib>
4 #include<cstring>
5 #include<cstdio>
6 #include<cmath>
7 using namespace std;
8 typedef long long ll;
9 const int N=1e5+10;
10 int h;
11 ll s[N];
12 int zz(int n){
13 int a[10];
14 while(n!=0){
15 a[h++]=n%10;
16 n/=10;
17 }
18 int ans=0;
19 for(int i=0;i<h;i++){
20 ans=ans*10+a[i];
21 }
22 return ans;
23 }
24 int main(){
25 int k,p;
26 ll ans;
27 while(~scanf("%d%d",&k,&p)){
28 for(int i=1;i<=k;i++){
29 h=0;
30 int x=zz(i);
31 s[i]=i*pow(10,h)+x;
32 }
33 ans=0;
34 for(int i=1;i<=k;i++){
35 ans=(ans+s[i])%p;
36 }
37 printf("%lld\n",ans);
38 }
39 return 0;
40 }

Codeforces 897 B.Chtholly's request-思维题(处理前一半)的更多相关文章

  1. Codeforces 718E - Matvey's Birthday(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\)​ 的 \((i,j)\)​ 之间都连了条边,而字符集大小顶多只有 \(8\ ...

  2. Codeforces 643F - Bears and Juice(思维题)

    Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 ...

  3. Codeforces 627E - Orchestra(双向链表,思维题)

    Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...

  4. Codeforces Round #416 (Div. 2)(A,思维题,暴力,B,思维题,暴力)

    A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...

  5. CodeForces 719A Vitya in the Countryside 思维题

    题目大意:月亮从0到15,15下面是0.循环往复.给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1. 题目思路:给出0则一定是UP,给出15一定是DOWN,给出其 ...

  6. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. codeforces 675 C ——Money Transfers——————【思维题】

    Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. CodeForces 492E Vanya and Field (思维题)

    E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. CodeForces 492D Vanya and Computer Game (思维题)

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. java前台传参json,后台用map或者实体对象接收

    (一)前台传js对象,里面包含数组,后台用map接收 (1)第一种情况:数组里不包含js对象 var param ={}: param.id=id; param.name=name; var scor ...

  2. centos使用--软件启动关闭等操作的命令

    关于centos服务的命令经常会遇到这几种 service systemctl /etc/init.d/ 1 service和/etc/init.d/ service是一个脚本命令,分析service ...

  3. adb logcat 日志过滤

    方法 1.采用wpa_supplicant:s   *:v 排除wpa_supplicant标签 adb -s 01d32e89cb94d599 logcat -v time -s wpa_suppl ...

  4. NSThread那些事儿

    NSThread 哎呀,它面向对象,再去看看苹果提供的API,对比一下Pthreads,简单明了,人生仿佛又充满了阳光和希望,我们先来一看一下系统提供给我们的API自然就知道怎么用了,来来来,我给你注 ...

  5. 用gulp清除、移动、压缩、合并、替换代码

    之前前端代码部署时用的是grunt,后来又出了个gulp工具,最近试用了一下,很方便,感觉比grunt简单好用,下面把一些常见的任务列一下,备用. var gulp = require('gulp') ...

  6. Json 转换 1 转成 true 0 转成false

  7. Linux系统源码安装cloud-init

    参考:https://cloud.tencent.com/document/product/213/12587使用以下命令下载 cloud-init 源码包 官网下载地址:https://launch ...

  8. hnust 好友互动标识

    问题 A: 好友互动标识 时间限制: 1 Sec  内存限制: 128 MB提交: 897  解决: 122[提交][状态][讨论版] 题目描述       QQ有一个有趣的功能即显示好友互动标识,它 ...

  9. c++知识点总结-模板特化

    类模板的全特化与偏特化 类模板 template<typename T1, typename T2> class Test { public: Test(T1 i,T2 j):a(i),b ...

  10. Mysql 查询—按位运算

    前言:虽说这是件小事儿,但本宝宝思前想后,还是为它留下一笔,嘿嘿.反正写博客不浪费纸和笔!好久没有开启我的逗比模式了,我亲爱的乖徒弟DBA,DBB,DBAA等,好久不见你们,遥祝幸福快乐+DB. 整个 ...