题解 CF630L Cracking the Code

前言

为什么没有人暴力快速幂啊,Ta不香嘛/kel

题意

设读入为 (abcde) ,求 (acedb^5mod{10^5}) 的结果。

(sf{Solution})

显然暴力啊。

先把每一位求好然后把新数算出来。

快速幂就行了。

(sf{P.S.})

输出格式:一行,5个数字,没有间隔符。

若结果为 (0) 得输出00000

(sf{Code})

#include<iostream>
using namespace std;
#define ll long long
ll n;
const int mod=100000;
ll f(ll x,ll y)
{
    if(y==1)
        return x;
    ll q=f(x,y/2)%mod;
    q=(q*q)%mod;
    if(y%2==1)
        return (q*x)%mod;
    else return q%mod;
}//快速幂
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	ll m=(n/1000%10)+(n/10%10)*10+(n%10)*100+(n/100%10)*1000+(n/10000%10)*10000,q=f(m,5);//m为重新组装后的数
	if(q==0)
		cout<<"00000
";//特判0
	else cout<<q<<"
";
	return 0;
}
原文地址:https://www.cnblogs.com/CM-0728/p/13767823.html