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. BFS:CF356C-Compartments

    C. Compartments time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. Storm: 遇到问题总结

    1.没有ack : kafkaspout id 重复导致每次读最新没有数据. 2.由于storm提供的读取kafka的enternal工具存在bug,导致重复读取数据,致使数据不准确.storm bu ...

  3. mysql中外联和 is null 结合使用

    今天学习mysql ,碰到了一个问题:有部门表,员工表,员工表中有一个部门表的外键,查询没有员工的部门名称. 表结构如下: 员工表employees: 部门表department表: 题目很简单呢,信 ...

  4. 使用dnspod遭遇的奇特问题以及背后的原因与临时解决方法

    由于园子里有不少用户在使用dnspod,我们觉得有必要将这两天blogjava.net域名在dsnpod遇到的奇特问题分享一下,以免再有人踩着这个坑. 12月11日,我们登录到dnspod的后台时,大 ...

  5. 我给女朋友讲编程CSS系列(1) –添加CSS样式的3种方式及样式表的优先权

    如果说,原生态就是美,那么,我们就没有必要穿衣打扮. 网页是什么? 说白了,网页就是一堆[html标签]有序的搭配,让[CSS属性值]整整容,请[Javascript语言]处理一下事件. 一个人的整容 ...

  6. Webapp和后端交互检查测试

    除了功能,我们可以使用下面方法,查看交互过程,页面不能发现的问题: 什么是json 什么是json,json是什么,json如何使用 JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能 ...

  7. Leetcode with Python -> Array

    118. Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  8. Spring 简单而强大的事务管理功能

    开始之前 关于本教程 本教程将深入讲解 Spring 简单而强大的事务管理功能,包括编程式事务和声明式事务.通过对本教程的学习,您将能够理解 Spring 事务管理的本质,并灵活运用之. 先决条件 本 ...

  9. HDU 2440、HDU 3694多边形费马点

    1.http://acm.hdu.edu.cn/showproblem.php?pid=2440   按照题意知道是一个简单的多边形即凸包,但给出的点并没有按照顺序的,所以需要自己先求出凸包,然后在用 ...

  10. Java的代码转C#

    推荐个网站:点击打开链接 细节上有些小问题