您的当前位置:首页【CF 327C】【弱渣终于a题了】翻译 & 题解

【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;
}


因篇幅问题不能全部显示,请点此查看更多更全内容

Top