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 ...
随机推荐
- C#的常见算法(面试)
一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+--+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { ; ...
- idea的debug调试快捷键
1 2 3 4 5 6 7 8 9 10 F9 resume programe 恢复程序 Alt+F10 show execution point 显示执行断点 F8 ...
- DataTable数据修改,换列
增加列 DataTable table= new DataTable(); table.Columns.Add("ID", type ...
- web端/h5端账号密码的安全性问题
firefox一直提示让浏览器记住密码会有安全问题,但是一直未曾关注过到底是什么安全问题. 国庆节回家后发生的一件小事,让我深刻认识到让浏览器记住密码有多么不安全. 事情的起因是这样,家里wifi信号 ...
- Interviewe
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- ELK 完整部署和使用 - 每天5分钟玩转 Docker 容器技术(90)
上一节已经部署了容器化的 ELK,本节讨论如何将日志导入 ELK 并进行图形化展示. 几乎所有的软件和应用都有自己的日志文件,容器也不例外.前面我们已经知道 Docker 会将容器日志记录到 /var ...
- String类型
String字符串的length属性返回的是该字符串里面16位字符的数量,如果字符串包含double-byte的字符,那么返回的数量可能不对 字符串一旦创建就修改不了 var lang = “Ja ...
- Easy UI下拉列表默认选中(多行)与为文本框赋值
1.为单行文本框赋值 var data2 = $('#LoadArea').combobox("getData"); if (data2) { $('#id).combobox(' ...
- TF30042: The database is full. Contact your Team Foundation Server administrator.
TF30042: The database is full. Contact your Team Foundation Server administrator. 在一个阳光明媚的下午,迁入代码的时候 ...
- [转载] 应用于负载均衡的一致性哈希及java实现
转载自http://blog.csdn.net/haitao111313/article/details/7537799 这几天看了几遍一致性哈希的文章,但是都没有比较完整的实现,因此试着实现了一下, ...