Codeforces897B-Chtholly's request
来源:互联网 发布:怎么创造软件 编辑:程序博客网 时间:2024/06/05 20:01
— 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!
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, .
题解:i从1到k模拟,求出每一个回文数,再相加即为ans。
Code:
#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<cstdio>#include<cstdlib>#define ll long longusing namespace std;int a[100005],t;int Palindrome(int n){for(t=1;n;t++){a[t]=n%10;n/=10;}t--;int ans=0;for(int j=1;j<=t;j++)ans=ans*10+a[j];return ans;}ll power(int t){ll ans=1;for(int i=1;i<=t;i++)ans*=10;return ans;}int main(){int k,p;ll ans=0;scanf("%d%d",&k,&p);for(ll i=1;i<=k;i++)ans=(ans+Palindrome(i)+i*power(t))%p;printf("%I64d",ans);return 0;}
- Codeforces897B-Chtholly's request
- Codeforces897B Chtholly's request
- Codeforces897B Chtholly's request
- B. Chtholly's request
- cf-Chtholly's request(水)
- Chtholly's request (思维)
- CF-897B.Chtholly's request
- CF Round# 449 Div2 B. Chtholly's request
- Codeforces Round #449 (Div. 2) B. Chtholly's request
- Codeforces Round #449 (Div. 2) B. Chtholly's request (思维
- CF897B——Chtholly's request(关于回文数)
- Codeforces Round #449 (Div. 2) 897B. Chtholly's request
- 周赛的题目—Chtholly's request
- Codeforces Round #449 (Div. 2) B. Chtholly's request
- [easy]CodeForces-897B Chtholly's request 模拟/找规律
- Codeforces Round #449 (Div. 2) B Chtholly's request (预处理)
- codeforces 897 B. Chtholly's request【构造回文数+递推】
- Bad Request 404s
- CentOS 6.5 配置IP地址的三种方法
- 细说JavaScript中this指向问题
- 常用排序算法之希尔排序
- Python学习日记 第三天
- 题解
- Codeforces897B-Chtholly's request
- 设计模式初探之工厂方法模式
- Spring文件AOP编程
- mysql 存储过程调用 mybatis/hibernate
- ubuntu vim命令
- ML--SVM学习小结(二)
- 浅尝TensorFlow on Kubernetes
- 【JavaScript】通过一个例子认识prototype,constructor和instanceof
- 正则表达式及其在python上的应用