Codeforces Round #449 (Div. 2) 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 ispalindrome 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, .
回文数系列题目(经典算法): http://blog.csdn.net/computer_liuyun/article/details/27967963
【题意】:求前k个偶数位回文数之和%p的值。
【分析】:POJ 1150/2402/3247同类题目。直接写个判断偶数位回文数的函数,将整数n逆转,逆转的方法就是利用求余%和/的思想,此题总有一个常错的地方,就是m的平方和立方可能会超范围所以一定要用long long 或者_int64即可。或者用字符串表示,可能更加通俗易懂。
#include <bits/stdc++.h> using namespace std; typedef long long ll;
ll n,m,sum;
ll a[];
ll huiwen(ll n)//倒过来和的数与原来相等,那么就是回文数
{
ll ans=n,t=n;//ll ans=n 若不分偶数位,则为ans=0;
while(t)
{
ans=ans*+t%;
t/=;
}
return ans;
} int main()
{
cin>>n>>m;
for(ll i=;i<=n;i++)
{
sum=(sum+huiwen(i))%m;
}
printf("%lld\n",sum%m);
}
数字规律
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);\
cin.tie();\
cout.tie();
using namespace std;
const int maxn = 1e5+;
typedef long long LL;
typedef pair<int,int> P;
LL k,p; LL getnow(LL n)
{
char str[] = {};
sprintf(str,"%lld",n);
int len = strlen(str);
for(int i=len;i<len+len;i++)
str[i] = str[*len-i-];
LL cnt = ;
sscanf(str,"%lld",&cnt);
return cnt;
} void solve()
{
LL ans = ;
for(int i=;i<=k;i++)
ans = (ans+getnow(i)) % p;
// cout<<getnow(k)<<endl;
cout<<ans<<endl;
} int main()
{
// IO;
cin>>k>>p;
solve();
return ;
}
字符串
Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】的更多相关文章
- codeforces 897B Chtholly's request 偶数长度回文数
codeforces 897B Chtholly's request 题目链接: http://codeforces.com/problemset/problem/897/B 思路: 暴力求出这100 ...
- Codeforces Round #265 (Div. 2) C. No to Palindromes! 构建无回文串子
http://codeforces.com/contest/465/problem/C 给定n和m,以及一个字符串s,s不存在长度大于2的回文子串,如今要求输出一个字典比s大的字符串,且串中字母在一定 ...
- Codeforces Round #449 (Div. 1) Willem, Chtholly and Seniorious (ODT维护)
题意 给你一个长为 \(n\) 的序列 \(a_i\) 需要支持四个操作. \(1~l~r~x:\) 把 \(i \in [l, r]\) 的 \(a_i\) 加 \(x\) . \(2~l~r~x: ...
- Codeforces Round #449 (Div. 2)
Codeforces Round #449 (Div. 2) https://codeforces.com/contest/897 A #include<bits/stdc++.h> us ...
- Codeforces Round #449 (Div. 2)ABCD
又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #449 Div. 2 A B C (暂时)
A. Scarborough Fair 题意 对给定的长度为\(n\)的字符串进行\(m\)次操作,每次将一段区间内的某一个字符替换成另一个字符. 思路 直接模拟 Code #include < ...
- 897B. Chtholly's request#长度为偶数的回文数(模拟)
题目出处:http://codeforces.com/problemset/problem/897/B 题目大意:构造一个题意要求的zcy数之后取模 #include<iostream> ...
- Codeforces Round #449 (Div. 2)-897A.Scarborough Fair(字符替换水题) 897B.Chtholly's request(处理前一半) 897C.Nephren gives a riddle(递归)
A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #449 (Div. 2) D. Ithea Plays With Chtholly
题目链接 交互题. 题意:给你三个数n,m,k.让你完成至多m次互动,每次给你一个q,让你从n个位置选一个位置放这个数,覆盖已经放过的数.让你再m次使得n个位置的数不递减,达到直接退出. 解法:暴力, ...
随机推荐
- Unidirectional TSP UVA - 116 多段图的最短路
题目:题目链接 思路:从后往前进行dp,用next数组记录字典序最小的那一条路径 AC代码: #include <iostream> #include <cstdio> #in ...
- 子窗体与父窗体调用对方js方法
有时候为了减少一个页面内的代码量,会将部分内容放到子窗体中,如后台管理中用iframe来进行管理 <div> <iframe id="dviframe" src= ...
- Python linecache模块
Table of Contents 1. linecache 1.1. 其它 2. 参考资料 linecache 今天分享一个python的小模块: linecache, 可以用它方便地获取某一文件某 ...
- 部署 Windows PowerShell Web 访问
部署 Windows PowerShell Web 访问 适用对象:Windows Server 2012, Windows Server 2012 R2 Windows PowerShell® We ...
- 【Python Selenium】简单数据生成脚本
最近因工作需要,写了一个简单的自动化脚本,纯属学习,顺便学习下selenium模块. 废话不多说,直接上代码!! 这里一位大神重写了元素定位.send_keys等方法,咱们直接进行调用. 适用Pyth ...
- Android 使用剪贴板传递简单数据及复杂数据的方法
传递数据的场景在于不同页面之间跳转,需要携带数据:简单数据值指的是String, int等数据, 复杂数据指的是类 1. 使用剪贴板传递简单数据方法: 第一个页面里面放数据操作如下: Clipbo ...
- wordpress 区分多语言站点
$blog_title = get_bloginfo( 'name' ); $table_name = ''; if ( $blog_title == 'Driver Easy' ) { $table ...
- 零基础学习 Python 之字符串
初识字符串 维基百科对于字符串的定义式:字符串是由零个或者多个字符组成的有限串行.你之前学会敲的第一行 print 代码里的 "Hello World",就是一个字符串.字符串的本 ...
- MongoDB01——安装MangoDB
一.MongoDB的下载 到MongoDB的官网——https://www.mongodb.com/download-center/community,选择要下载的版本,点击Download 二.安装 ...
- JQuery向ashx提交中文参数方案 [转]
转自:http://blog.csdn.net/wangqiuyun/article/details/8450964 字符编码这个东西,一旦和中文打上交道就不可避免出现乱码,今天项目用到了JQuery ...