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 ...
随机推荐
- PowerDesigner如何将一个包里的表拷贝到另一个表以后在视图中也可以显示?
第一步:选中PhysicalDiagram_1 第二步:点击:“ Symbol”按钮, 第三步:点击“Show Symbols”,出现如下界面 第四步:选中State.
- IOS客户端的个人中心可以查看自己的博客了。
IOS客户端的个人中心可以查看自己的博客了. 写这篇是为了在客户端显示之用. 下一步实现在客户端发博客.
- jpg、png、gif图片格式的浅析
原文地址:图片格式与设计那点事儿 之前面试时被面试官问到了jpg.gif.png格式的区别,当时就扯了一些,感觉都是扯淡,上网搜了下,分享一篇文章 第一次写技术博客,有不尽如人意的地方,还请见谅和指正 ...
- appium-手势密码实现-automationName 是automator2
上一篇博客已经说了 appium-手势密码实现-automationName 是Appium的情况 下面就说一下automator2的情况: 手势密码的moveTo方法的参数进行了改变. 参数是相对于 ...
- 设计模式之模板方法模式 templateMethod
代码实现 public abstract class BankTemplateMethod { //具体方法 public void takeNumber(){ System.out.println( ...
- python杂七杂八知识点
1.中文编码问题解决办法:# _*_ coding:UTF8 _*_ 2.numpy.ndArray a = array([[1,2,3], [4, 5, 6]]) 3.numpy.argsort() ...
- jsp页面中引入java类
<%@ page import="java.util.*" %>
- 软工实践 - 第十七次作业 Alpha 冲刺 (8/10)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/articles/10023469.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长 ...
- hdu1712 分组背包 ACboy needs your help
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 201621123034 《Java程序设计》第11周学习总结
作业11-多线程 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread ...