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 ...
随机推荐
- LeetCode 112. Path Sum (二叉树路径之和)
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- git合并代码解决冲突
一直测试的我,之前有接触过git命令,但是没有详细的去看这些命令的意思,只是背着在用,今天一时兴起,看到了廖雪峰的git方面的博客<a href="https://www.liaoxu ...
- 业余草双因素认证(2FA)教程
所谓认证(authentication)就是确认用户的身份,是网站登录必不可少的步骤.密码是最常见的认证方法,但是不安全,容易泄露和冒充.越来越多的地方,要求启用双因素认证(Two-factor au ...
- 如何获取系统Home(Launcher)应用判断用户是否处于home界面
要把我们的应用程序作为home(launcher应用),只需要在AndroidManifest.xml中添加: <category android:name="android.inte ...
- Ruby on Rails---Active Admin使用(一)
概述 Active Admin提供了一个友好的后台管理界面,将CRUD等操作可视化,操作极其方便 安装 1. 添加gem gem "devise", :github => ' ...
- Java反射机制能够获取的信息,与应用
一.什么是Java反射机制? [1]反射机制是在运行状态中,对于任何一个类,都能够知道这个类的所有属性和方法: [2]对于任意一个对象,都能够调用它的任意一个属性和方法: 像这种动态获取类的信息以及动 ...
- hdu 3001 Travelling(状态压缩 三进制)
Travelling Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- sass学习--安装ruby
1.下载ruby:https://rubyinstaller.org/downloads/ 2.安装完ruby之后,在开始菜单中,找到刚才我们安装的ruby,打开Start Command Promp ...
- linux 更新源miss问题
1.之前新装的linuxMint 执行 apt-get install vim 安装失败 发现原因是源更新失败导致,后来执行apt-get update 发现老是获取失败,查了google总结出以下解 ...
- 如何在C#中使用存储过程(SQL Server 2000)
要在C#中使用存储过程,首先看看test表的创建sql语句: create table test55 ( uid int identity(1,1), class1 varchar(20), cl ...