HDU 1452

和上题一样,不过,更简单了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

const int MOD=29;

int quick(int a,int b,int m){
	int res=1;
	while(b){
		if(b&1){
			res=(res*a)%m;
		}
		b=b>>1;
		a=(a*a)%m;
	}
	return res;
}

int main(){
	int a,b,c;
	a=2;b=3;c=167;
	int x;
	while(scanf("%d",&x),x){
		int ax=2*x; int bx=x; int cx=x;
		int ans=1;
		int p,q;
		p=quick(a,ax+1,MOD);
		p=((p-1)%MOD+MOD)%MOD;
		q=quick(a-1,MOD-2,MOD);
		ans=(ans*((p*q)%MOD))%MOD;
		p=quick(b,bx+1,MOD);
		p=((p-1)%MOD+MOD)%MOD;
		q=quick(b-1,MOD-2,MOD);
		ans=(ans*((p*q)%MOD))%MOD;
		p=quick(c,cx+1,MOD);
		p=((p-1)%MOD+MOD)%MOD;
		q=quick(c-1,MOD-2,MOD);
		ans=(ans*((p*q)%MOD))%MOD;
		printf("%d
",ans);
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/jie-dcai/p/3969570.html