Codeforces 897 B.Chtholly's request-思维题(处理前一半)
2 seconds
256 megabytes
standard input
standard output
— 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,
.
题意就是回文,而且回文的长度是偶数,将前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-思维题(处理前一半)的更多相关文章
- Codeforces 718E - Matvey's Birthday(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 首先注意到这个图的特殊性:我们对于所有 \(s_i=s_j\) 的 \((i,j)\) 之间都连了条边,而字符集大小顶多只有 \(8\ ...
- Codeforces 643F - Bears and Juice(思维题)
Codeforces 题目传送门 & 洛谷题目传送门 首先直接暴力枚举显然是不现实的,我们不妨换个角度来处理这个问题,考虑这 \(R_i\) 个瓶子中每一瓶被哪些熊在哪一天喝过. 我们考虑对这 ...
- Codeforces 627E - Orchestra(双向链表,思维题)
Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...
- 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 ...
- CodeForces 719A Vitya in the Countryside 思维题
题目大意:月亮从0到15,15下面是0.循环往复.给出n个数字,如果下一个数字大于第n个数字输出UP,小于输出DOWN,无法确定输出-1. 题目思路:给出0则一定是UP,给出15一定是DOWN,给出其 ...
- Codeforces 671 A——Recycling Bottles——————【思维题】
Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 675 C ——Money Transfers——————【思维题】
Money Transfers time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CodeForces 492E Vanya and Field (思维题)
E. Vanya and Field time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 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 ...
随机推荐
- 使用Windows SFC和DISM工具来解决服务器OS问题
TechTarget中国原创] 随着使用时间的越来越多,Windows服务器安装的系统文件可能会被损坏或损毁.管理员一般可以通过系统自带的System File Checker (SFC) 或者更健壮 ...
- ScrollView中ViewPager无法正常滑动问题
本文主要介绍如何解决ViewPager在ScrollView中滑动经常失效.无法正常滑动问题. 解决方法只需要在接近水平滚动时ScrollView不处理事件而交由其子View(即这里的ViewPage ...
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目5
2014-03-20 03:23 题目:给定一个字符串,输出其全排列. 解法:可以调用STL提供的next_permutation(),也可以自己写一个.对于这种看起来简单的题目,应该在能优化的地方, ...
- 七夕蠕虫“XX神器”逆向分析
转载请注明出处 ____________________________________________________________________________________________ ...
- day06_01 上节回顾
1.0 extend 扩展方法及"+"的对比 "+"不会改变数组的内容,而extend会改变数组的内容 2.0 sort扩展sorted() a = [1,2, ...
- 孤荷凌寒自学python第四天 安装python的其它IDE环境
孤荷凌寒自学python第四天 安装python的其它IDE环境 (完整学习过程屏幕记录视频地址在文末) 因为是完全的新手,对python环境搭建完全一无所知,因此,可真是大费周章才配置了其它多个Id ...
- C# MemoryCache 类[转载]
原网址:http://www.cmono.net/post/read/156 MemoryCache 类是.Net .0推出的类库,主要是为了方便在Winform和Wpf中构建缓存框架的 Object ...
- CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]
原文:http://www.cnblogs.com/chenrui7/p/3592082.html 今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net ...
- HTML5应用:setCustomValidity(message)接口
本文转自http://tid.tenpay.com/?p=3592 HTML5表单验证给前端人员带来了便利,但是在用户体验上存在一些缺陷,默认的提示对用户很不友好,无法准确的获取想要的信息.好在大牛们 ...
- PHP面向对象 封装与继承
知识点: PHP封装三个关键词: 一.public 公有的,被public修饰的属性和方法,对象可以任意访问和调用 二.private 私有的,被private修饰的属性和方法,只能在类内部的方法可以 ...