zoukankan      html  css  js  c++  java
  • 模板—十进制快速幂

    用于指数爆longlong的情况,当然你也可以打高精……

    因为昨天有人提到了慢速乘,感觉挺有用的,就顺便都学了吧,而且省选也用到十进制快速幂了。

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #define LL long long
    using namespace std;
    char c[100000];
    LL a,p,t;
    LL tenthpow(LL a)
    {
    	LL ans=1,s=a;
    	while(t>=0)
    	{
    		LL cnt=c[t]-'0',cur=s;
    		for(int i=1;i<=cnt;i++)
    		ans=ans*s%p;
    		for(int i=1;i<10;i++)
    		cur=cur*s%p;
    		s=cur;ans%=p;t--;
    	}
    	return ans;
    }
    signed main()
    {
    	cin>>a>>c>>p;
    	t=strlen(c);t--;
    	cout<<tenthpow(a)<<endl;
    }
    
  • 相关阅读:
    asp.net读取/导入project(mpp)文件
    hdu2103
    hdu2100(大数加)
    hdu1406
    hdu1249
    hdu1038
    hdu2565
    hdu1203
    zoj3501
    hdu2102
  • 原文地址:https://www.cnblogs.com/Al-Ca/p/11186778.html
Copyright © 2011-2022 走看看