求回文数字

题目

题意:

定义:一个数字,如果它是回文的(也就是正着念和反着念是是一样的)并且它的长度是偶数,那么就把它称为zcy数。

求出前k个最小的zcy数的和,再mod P的值。

题解:

仔细观察,能够发现第x个zcy数是把x正着写一遍,再把x反正写一遍。

比如1,zcy数是11,7的zcy数是77,123的zcy数是123321。

所以求出每个小于100000的数对应的zcy数就好了。

#pragma warning(disable:4996)
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f;
ll ans[100005];
void init()
{
	ll temp, i, j,t;
	for (i = 1; i <= 100000; i++)
	{
		temp = i;
		t = i;
		while(t)
		{
			temp = temp * 10 + t % 10;
			//temp乘上10,再加上t的最后一位。
			//比如123,temp先等于123,乘上10,加上3就是1233
			//然后接着求后面的数字,temp依次等于12332,123321
			t /= 10;
		}
		ans[i] = temp;
	}
}
int main()
{
	ll k, p,res=0,i;
	init();
	scanf("%lld%lld", &k, &p);
	for (i = 1; i <= k; i++)
	{
		res = (res + ans[i]) % p;//求出mod p的答案。
	}
	printf("%lld\n", res);
	return 0;
}

 

    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值