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 ;
}

字符串

Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】的更多相关文章

  1. codeforces 897B Chtholly's request 偶数长度回文数

    codeforces 897B Chtholly's request 题目链接: http://codeforces.com/problemset/problem/897/B 思路: 暴力求出这100 ...

  2. Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子

    http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...

  3. Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)

    题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...

  4. Codeforces Round #449 (Div. 2)

    Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...

  5. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Round #449 Div. 2 A B C (暂时)

    A. Scarborough Fair 题意 对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符. 思路 直接模拟 Code #include < ...

  7. 897B. Chtholly's request#长度为偶数的回文数(模拟)

    题目出处:http://codeforces.com/problemset/problem/897/B 题目大意:构造一个题意要求的zcy数之后取模 #include<iostream> ...

  8. Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)

    A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly

    题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...

随机推荐

  1. CF 497 div 2 B

    B. Turn the Rectangles time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. ListNode Java创建链表

    用了一种自创的比较简洁的方式来创建链表 class ListNode { //为了方便,这两个变量都使用pub1ic, //存放数据的变量,直接为int型 public int data; //存放结 ...

  3. 笔记-编程-IO模型

    笔记-编程-IO模型 1.      简介 常用IO模型 1)      同步阻塞IO(Blocking IO) 2)      同步非阻塞IO(Non-blocking IO) 3)      IO ...

  4. flex遭遇text-overflow:hidden,white-space:nowrap

    最近在项目中遇到使用flex的时候,在flex-item元素中使用text-overflow:hidden:white-space:nowrap:进行省略文字的操作. 发现flex-item失控了,长 ...

  5. 移动web前端开发小结

    注意:Chrome模拟手机的显示的界面是有误差的,强烈建议一定要在真机测试自己的移动端页面(以移动端页面为准). 1.页面高度渲染错误,页面的高度是否包含了导航,(华为手机就是偏偏有底部菜单) 设置窗 ...

  6. python week09 Mysql 数据库基础知识

    第一篇:初识数据库 注:<基础概念,不再赘述,点开链接查看> 第二篇:库相关操作 一 系统数据库 information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些 ...

  7. psql 工具详细使用介绍

    psql 介绍 psql 是 PostgreSQL 中的一个命令行交互式客户端工具, 它允许你交互地键入 SQL 命令,然后把它们发送给 PostgreSQL 服务器,再显示 SQL 或命令的结果. ...

  8. CSU-2220 Godsend

    题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2220 题目 Description Leha somehow found ...

  9. Spring框架配置beans.xml

    Spring学习笔记(一) 一.Spring 框架 Spring 是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的主要优势之一就是其分层架构,分层架构允许您选择使用哪一个组件,同时为 ...

  10. iOS-@inerface的11条规范写法

    总结一些interface声明时的规范,相关宏的介绍,定义方法时有用的修饰符,编写注释的规范,最终写出一个合格的头文件. 1.读写权限 1.1实例变量的@public,@protected,@priv ...