449B
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,
.
输入n和m,得到前n个长度是偶数的回文数的和 sum,输出sum模上m的值,
本来用了暴力去解, 但是爆掉了,本来我是从1开始检测,一直检测到第n个符合条件的数结束,
但是测试数据里有这样一组数
42147 412393322
#include<stdio.h>
#include<string.h>
int main()
{
int m,n,i,t,j,h,len,k,d[],a,b;
long long sum;
char p[];
h=;
for(i=;i<=;i++)
{
k=;
d[]=;
sprintf(p,"%d",i);
len=strlen(p);
if(len%==)
{ for(j=;j<(len+)/;j++)
if(p[j]!=p[len-j-])
{k=;break;}
if(k==)
{ d[h+]=d[h]+i;
h++;
}
}d[i]=d[h]; }
while(scanf("%d%d",&n,&m)!=EOF)
{
printf("%d\n",d[n+]%m);
}
}
AC的代码:
#include<stdio.h>
int main()
{
int m,a,b,i,j;
long long n,t,t1,sum;
while(scanf("%lld%d",&n,&m)!=EOF)
{
sum=;
for(i=;i<=n;i++)
{
t=t1=i;
while(t!=)
{
t1=t1*+t%;
t/=;
}
sum=(sum+t1)%m;
} printf("%lld\n",sum);
}
}
449B的更多相关文章
- Aizu 2249 & cf 449B
Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...
- Codeforces 449B
题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces 449B Jzzhu and Cities (Dij+堆优化)
输入一个无向图<V,E> V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...
- Codeforces Round #257 (Div. 1) (Codeforces 449B)
题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...
- Codeforces449A Jzzhu and Chocolate && 449B Jzzhu and Cities
CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀, ...
- [Codeforces 449B] Jzzhu and Cities
[题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...
- CodeForces - 449B 最短路(迪杰斯特拉+堆优化)判断最短路路径数
题意: 给出n个点m条公路k条铁路. 接下来m行 u v w //u->v 距离w 然后k行 v w //1->v 距离w 如果修建了铁路并不影响两点的最短距离, ...
- 超越 JSON: Spearal 序列化协议简介
Spearal 是一个新的开源的序列化协议,这个协议旨在初步替换JSON 将HTML和移动应用连接到Java的后端. Spearal的主要目的是提供一个序列协议,这个协议即使是在端点间传输的复杂的 ...
- 蒟蒻修养之cf橙名计划
因为太弱,蒟蒻我从来没有上过div1(这就是今年的最后愿望啊啊啊啊啊)已达成................打cf几乎每次都是fst...........所以我的cf成绩图出现了惊人了正弦函数图像.. ...
随机推荐
- addEventListener event
addEventListener 先看个例子: document.getElementById("myBtn").addEventListener("click&qu ...
- appium支持的版本
appium 支持4.2以上的版本 2.3-4.1的版本的支持通过Selendroid实现
- YTUOJ-推断字符串是否为回文
题目描写叙述 编敲代码,推断输入的一个字符串是否为回文.若是则输出"Yes",否则输出"No".所谓回文是指順读和倒读都是一样的字符串. 输入 输出 例子输入 ...
- Snail—iOS网络学习之得到网络上的数据
在开发项目project中,尤其是手机APP,一般都是先把界面给搭建出来.然后再从网上down数据 来填充 那么网上的数据是怎么得来的呢,网络上的数据无非就经常使用的两种JSON和XML 如今 大部分 ...
- asp.net+access实现DropDownList与RadDatePicker同步筛选
这里没有使用SqlServer是因为老师要求使用access. 前台代码 <table style="margin:auto"> <tr><td cl ...
- mybatis xml文件解析
1 parameterType 如果参数只有一个,比如一个id,即int类型的id,那么parameterType直接是int. 如果参数有多个,那么就用表中一行对应的类,默认是类的名字和表中列的名字 ...
- 新手必备的SEO优化工具
- a column-oriented DBMS
https://clickhouse.yandex/docs/en/introduction/what_is_clickhouse.html
- 用Qt编写的计算文件MD5值的Demo
Dialog.ui <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0& ...
- node-orm2
最近应老大要求,对orm2进行再一步封装,所以记录下封装和使用心得(文中数据库:mysql). 数据库连接 var orm = require("orm"); orm.connec ...