B. Chtholly's request
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

— Thanks a lot for today.

— 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!

Input

The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

Output

Output single integer — answer to the problem.

Examples
Input
2 100
Output
33
Input
5 30
Output
15
Note

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
 也就是说要检测到第42147个符合要求的回文数才算结束,结果TLE了,最后发现规律,第i个回文数就是把i反转出现的数。
TLE的代码:
#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的更多相关文章

  1. Aizu 2249 & cf 449B

    Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...

  2. Codeforces 449B

    题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. codeforces 449B Jzzhu and Cities (Dij+堆优化)

    输入一个无向图<V,E>    V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...

  4. Codeforces Round #257 (Div. 1) (Codeforces 449B)

    题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...

  5. Codeforces449A Jzzhu and Chocolate && 449B Jzzhu and Cities

    CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀, ...

  6. [Codeforces 449B] Jzzhu and Cities

    [题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...

  7. CodeForces - 449B 最短路(迪杰斯特拉+堆优化)判断最短路路径数

    题意: 给出n个点m条公路k条铁路. 接下来m行 u v w      //u->v 距离w 然后k行 v w         //1->v 距离w 如果修建了铁路并不影响两点的最短距离, ...

  8. 超越 JSON: Spearal 序列化协议简介

      Spearal 是一个新的开源的序列化协议,这个协议旨在初步替换JSON 将HTML和移动应用连接到Java的后端. Spearal的主要目的是提供一个序列协议,这个协议即使是在端点间传输的复杂的 ...

  9. 蒟蒻修养之cf橙名计划

    因为太弱,蒟蒻我从来没有上过div1(这就是今年的最后愿望啊啊啊啊啊)已达成................打cf几乎每次都是fst...........所以我的cf成绩图出现了惊人了正弦函数图像.. ...

随机推荐

  1. lodar

    一个文件使用另一个文件的东西的时候需要使用到 export{开放} --watch 自动检测 可以加载打包的后边 module.exports = { entry:{ //入口文件 home:&quo ...

  2. 【python】How to change the Jupyter start-up folder

    Copy the Jupyter Notebook launcher from the menu to the desktop. Right click on the new launcher and ...

  3. android控件之间事件传递

    public boolean dispatchTouchEvent(MotionEvent ev){} 用于事件的分发.Android中全部的事件都必须经过这种方法的分发.然后决定是自身消费当前事件还 ...

  4. JS中prototype,js原型扩展

    作者:轩脉刃(yjf512)出处:(http://www.cnblogs.com/yjf512/)版权声明:本文的版权归作者与博客园共有.欢迎转载阅读,转载时须注明本文的详细链接. 原文 http:/ ...

  5. Typescript 常见写法

    一.Typescript 中数组 let list: number[] = [1, 2, 3]; let list: Array<number> = [1, 2, 3];

  6. react native 之页面跳转

    第一章  跳转的实现 1.component  中添加这行代码 <View style={styles.loginmain}> <Text style={styles.loginte ...

  7. android adb 源码框架分析(1 系统)【转】

    本文转载自:http://blog.csdn.net/luansxx/article/details/25203269 ‘ Adb模块包括adb,adbd,源代码都在system/core/adb目录 ...

  8. HDU 1022 之 Train Problem I

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. 字典树(Trie树) C++实现

    说明: 以下代码是个人按照自己的理解写的,可能有错误或者不太规范的地方,欢迎指出! 代码如下: //插入.删除.查询.遍历四种操作 //注意:四种操作的函数实现中,T都是指向上一个结点的指针,以此方便 ...

  10. 请问snmp到底是干啥的。

    这个事情分两方面来说:首先是路由器这部分.路由器开启SNMP功能之后,它能够对自己的每个接口上的流量有一个统计,当然统计的不单单只有流量.然后路由器把统计到的内容按一定的格式保存起来.这个格式是大家都 ...