python 练习-回文数字

如果一个数是回文并且它没有前导零, 它的长度为偶数, 我们叫这样一个数为一个zcy数。当一个数是回文, 这个数没有前导零并且反着读和它本身一样。例如, 12321和1221是回文, 123和12451不是回文。此外, 1221是zcy数, 12321不是。

Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.

给出整数k和p, 计算前k大的zcy数的和, 输出这个和对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).

第一行包括两个整数k和p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).

输出 / Output
Output single integer \— answer to the problem.

输出一个整数 - 问题的答案.

样例 / Example
input1
2 100

output1
33

input2
5 30

output2
15

k, p = map(int, input().split())
res = 0

#解法1
for i in range(1, k+1):
    res += int(str(i)+str(i)[::-1])
print(res % p)

#解法2
a = [11,22,33,44,55,66,77,88,99]
s = 0
for i in range(k):
    s+=a[i]
print(s%p)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值