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

      

  • 相关阅读:
    AC自动机
    哈希与哈希表
    Trie字典树
    整除
    P3375 【模板】KMP字符串匹配
    KMP算法
    Luogu-P1004 方格取数
    Luogu-P2758 编辑距离
    Luogu-P1018 乘积最大
    Luogu-P1880 [NOI1995]石子合并
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/3969570.html
Copyright © 2020-2023  润新知