codeforces 897B Chtholly's request 偶数长度回文数
codeforces 897B Chtholly's request
题目链接:
http://codeforces.com/problemset/problem/897/B
思路:
暴力求出这100000个偶数回文数,说是暴力,其实是直接求出,O(n)。然后累加求和取模即可。注意WA test 12是因为没有求导最后一个回文数,心痛啊,调了一个半小时最后没检查出来,一定要注意范围
代码:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
ll index=0;
ll b[100005];
ll mod,n,sum;
void init() {
for(ll i=1;i<=9;++i) {
b[index]=i*10+i;
index++;
}
for(ll i=1;i<=9;++i) {
for(ll j=0;j<=9;++j) {
b[index]=i*1000+j*100+j*10+i;
index++;
}
}
for(ll i=1;i<=9;++i) {
for(ll j=0;j<=9;++j) {
for(ll k=0;k<=9;++k) {
b[index]=i*100000+j*10000+k*1000+k*100+j*10+i;
index++;
}
}
}
for(ll i=1;i<=9;++i) {
for(ll j=0;j<=9;++j) {
for(ll k=0;k<=9;++k) {
for(ll x=0;x<=9;++x) {
b[index]=i*10000000+j*1000000+k*100000+x*10000+x*1000+k*100+j*10+i;
index++;
}
}
}
}
for(ll i=1;i<=9;++i) {
for(ll j=0;j<=9;++j) {
for(ll k=0;k<=9;++k) {
for(ll x=0;x<=9;++x) {
for(ll y=0;y<=9;++y) {
b[index]=i*1000000000+j*100000000+k*10000000+x*1000000+y*100000+y*10000+x*1000+k*100+j*10+i;
index++;
}
}
}
}
}
b[index]=100000000001;
index++;
sort(b,b+index);
}
int main() {
init();
while(~scanf("%I64d %I64d",&n,&mod)) {
sum=0;
for(int i=0;i<n;++i) sum=(sum%mod+b[i]%mod)%mod;
printf("%I64d\n",sum);
}
return 0;
}
codeforces 897B Chtholly's request 偶数长度回文数的更多相关文章
- Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】
B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 897B. Chtholly's request#长度为偶数的回文数(模拟)
题目出处:http://codeforces.com/problemset/problem/897/B 题目大意:构造一个题意要求的zcy数之后取模 #include<iostream> ...
- [LeetCode] Prime Palindrome 质数回文数
Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...
- 洛谷 U3346 A1-偶回文数
U3346 A1-偶回文数 题目背景 方方方很喜欢回文数,于是zzq就出了一道关于回文数的题目. 因为偶回文数比较简单,所以方方方就把它放在了第一题... 题目描述 我们定义一个长度为偶数的回文数叫做 ...
- CodeForces 688B Lovely Palindromes (水题回文)
题意:给一个数n,让你找出长度为偶数,并且是第 n 个回文数. 析:你多写几个就知道了,其实就是 n,然后再加上n的逆序,不过n有点大,直接用string 好了. 代码如下: #include < ...
- 判断回文字符串、回文链表、回文数(python实现)
所谓回文字符串,就是正读和反读都一样的字符串,比如"level"或者"noon"等等就是回文串.即是对称结构 判断回文字符串 方法一: def is_palin ...
- [2014亚马逊amazon] 在线笔试题 大于非负整数N的第一个回文数 Symmetric Number
1.题目 如标题,求大于整数N(N>=0)的第一个回文数的字符串表示形式. 这个题目也是当时笔试第一次见到,花了一个小时才做出了.慢慢总结还是挺简单的. 2.分析 分析如下: (1)一位数N(9 ...
- tmp_获取下一个回文数
直接拿之前一次竞赛中写的code,稍微完善了点,后面有机会在优化 uint64_t GetNextPalindrome(uint64_t data) { //100以内的数字已经特殊考虑过,不存在差值 ...
- [LeetCode] 906. Super Palindromes 超级回文数
Let's say a positive integer is a superpalindrome if it is a palindrome, and it is also the square o ...
随机推荐
- jdbc链接hive报错:java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport
写了个jdbc连接hive2的demo,结果报错:java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport,实际 ...
- c++ 类的默认八种函数
c++ 类的默认八种函数 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #incl ...
- counter 计数器
包含了两个属性和一个方法: 1. counter-reset 2. counter-increment 3. counter()/counters() counter-reset(主要作用就是给计 ...
- [J2EE] 有关 PreparedStatement
今天同事遇到一个问题,简言之,就是PreparedStatement的预编译究竟是怎么发挥作用的... 嘿嘿,说来惭愧,我以前就只知道PreparedStatement比Statement要好,要防S ...
- sql分区文件删不的可能解决方法
删除数据库分区的时候报错如下: ALTER DATABASE [ITMP2] remove FILE F20170427Msg 5042, Level 16, State 1, Line 1The f ...
- 深入探讨List<>中的一个姿势。
List<>是c#中很常见的一种集合形式,近期在阅读c#源码时,发现了一个很有意思的定义: [DebuggerTypeProxy(typeof(Mscorlib_CollectionDeb ...
- Servlet编程实例2
上次实验中利用HttpServletRespon.sendRedict()方法来实现页面的转跳,而这种重定向请求的方法无法传递缓存的内容. 所以为了做出改进,这次使用RequestDispatcher ...
- sublime text3添加右键打开的操作
前一段重新安装了Sublime Text3,不过一直不在右键菜单中,所以决定添加,有如下2种方法. 方法一(推荐). 把以下代码,复制到SublimeText3的安装目录,然后重命名为:sublime ...
- [转载] Rss 与 Feed 的概念区别
转载自http://www.chinaz.com/news/2011/0831/207961.shtml 可能很多刚刚接触博客的童鞋们,也和我一样不太了解:rss和feed概念或者说不了解rss和fe ...
- [转载] KAFKA分布式消息系统
转载自http://blog.chinaunix.net/uid-20196318-id-2420884.html Kafka[1]是linkedin用于日志处理的分布式消息队列,linkedin的日 ...