【CF 327C】【弱渣终于a题了】翻译 & 题解

本题的意思就是给你一个高精数字,之后把它复制k遍链接起来 (例如: 1234 2 处理为 12341234)

然后去掉这个数字中的某些数,使它能被5整除(005和05也算 且属于两种情况)



只要尾数是5或0就能被5整除

所以当你选定一个数字是0或5时,需要把它后面的数全部删除,前面的数可选可不选,总共有2^n种(n为此数前面的数的个数)

然后等比数列求和,公比为2^size(num)


额下面是代码


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
const long long mod=1000000007;
string x;
int k;
LL ans=0;
LL q;
LL ex_gcd(LL a,LL b,LL& x,LL& y)
{
	if(a==0)
	{
		x=0;
		y=1;
		return b;
	}
	LL ans=ex_gcd(b%a,a,y,x);
	x-=b/a*y;
	return ans;
}
long long ksm(int n,int x,int moda=mod)
{
	if(n==1)
		return x;
	if(n==0)
		return 1;
	long long ans=ksm(n/2,x);
	if(n%2==0)
		return ans*ans%moda;
	return ans*ans%moda*x%moda;
}
int main()
{
	cin>>x>>k;
	for(int i=0;i<x.size();i++)
		if(x[i]=='0' || x[i]=='5')
			ans+=ksm(i,2);
	q=ksm(x.size(),2);
	LL ny;
	LL x;
	ex_gcd(q-1,mod,ny,x);
	LL eans=ans%mod*(ksm(k,q)-1)%mod*ny%mod;
	cout<<(eans+mod)%mod<<endl;
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值