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 ...
随机推荐
- java文件基本操作
public static void main(String [] args) { try { /* * File类 */ /*String directory = "D:/Workspac ...
- 哪些工具能有效管理Azure Active Directory?
[TechTarget中国原创] 管理Azure Active Directory有四种常见的工具:Azure Web门户.Azure PowerShell.Azure命令行接口和Azure Mana ...
- android gesture检测
1.关于on<TouchEvent>的返回值 a return value of true from the individual on<TouchEvent> methods ...
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目1
2014-03-21 20:35 题目:给定已升序排列的数组A和数组B,如果A有足够的额外空间容纳A和B,请讲B数组合入到A中. 解法:由后往前进行归并. 代码: // 11.1 Given two ...
- python学习笔记十二:类的定义
demo #!/usr/bin/python class Person: name = 'jim' age = 25 def say(self): print 'My name is ' + self ...
- 【Lowest Common Ancestor of a Binary Search Tree】cpp
题目: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in th ...
- python 学习分享-paramiko模块
paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Solaris, BS ...
- docker部署思路
1.docker安装2.拉取centos镜像或者Ubuntu镜像 看你用哪个3.使用镜像,run出来一个容器A4.进入容器A,安装uwsgi,把Django部署在下面5.在启动脚本中配置开机自启动脚本 ...
- Vim常用指令总结(持续更新中)
1 模式变更 命令 说明 a(append)/i(insert) 普通模式→插入模式 : 普通模式→命令行模式 ESC或者Ctrl 插入模式→普通模式 R(Replace)/Insert两次 普通模式 ...
- 附录:python and numpy
http://cs231n.github.io/python-numpy-tutorial/ Python is a great general-purpose programming languag ...