Codeforces Round #449 (Div. 2) B. Chtholly's request
来源:互联网 发布:期货软件哪个好 编辑:程序博客网 时间:2024/06/15 01:48
— 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!
The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).
Output single integer — answer to the problem.
2 100
33
5 30
15
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~k,就是回文数的一半,比如1,2,3,4是(11,22,33,44)的一半,所以长度为偶数,我们只用枚举它的前一半。然后就是求它的另外一半,求一半的时候可以注意规律,例如1221=(12*10+12%10))*10+(12/10)%10。注意数据可能会超过int所以要用long long。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
long long int sum=0;
int main()
{
int k,p,j;
scanf("%d %d",&k,&p);
for(int i=1; i<=k ;++i)
{
j=i;
int a;
long long int temp=i;
while(j)
{
a=j%10;
temp=temp*10+a;
j/=10;
}
sum+=temp;
}
printf("%d\n",sum%p);
return 0;
}
- Codeforces Round #449 (Div. 2) B. Chtholly's request
- Codeforces Round #449 (Div. 2) B. Chtholly's request (思维
- Codeforces Round #449 (Div. 2) 897B. Chtholly's request
- Codeforces Round #449 (Div. 2) B. Chtholly's request
- Codeforces Round #449 (Div. 2) B Chtholly's request (预处理)
- CF Round# 449 Div2 B. Chtholly's request
- Codeforces Round #449 (Div. 1) B. Ithea Plays With Chtholly
- B. Chtholly's request
- [easy]CodeForces-897B Chtholly's request 模拟/找规律
- Codeforces Round #449 (Div. 1) C. Willem, Chtholly and Seniorious
- Codeforces Round #449 (Div. 1) E. Welcome home, Chtholly
- CF-897B.Chtholly's request
- codeforces 897 B. Chtholly's request【构造回文数+递推】
- Codeforces Round #248 (Div. 2) B - Kuriyama Mirai's Stones
- Codeforces Round #248 (Div. 2) B Kuriyama Mirai's Stones
- Codeforces Round #248 (Div. 2) B - Kuriyama Mirai's Stones
- Codeforces Round #323 (Div. 2) B. Robot's Task
- Codeforces Round #323 (Div. 2) B. Robot's Task
- Python实现浅层神经网络
- 工业相机的基本参数以及选型参考
- SSH Exception 2017.3.27-3 ERROR StatusLogger No log4j2 configuration file found
- 欢迎使用CSDN-markdown编辑器
- Echarts实现柱状图、雷达图、时间轴联动
- Codeforces Round #449 (Div. 2) B. Chtholly's request
- 聊聊在小米实习的日子
- Python向MySQL批量插数据
- 数据结构与算法分析——C语言描述3.3
- codeforces895A Pizza Seperation
- 我的lua 学习
- Android自定义导航图文按钮ImageTextButton
- Python机器视觉编程常用的数据结构
- 模块化