UVa 374 Big Mod

简介: UVa 374 Big Mod
#include <stdio.h>unsignedlongbigmod(unsignedlongb, unsignedlongp, unsignedlongm);
unsignedlongsquare(unsignedlonga);
intmain()
{
unsignedlongb, p, m, res;
#ifndef ONLINE_JUDGEfreopen("d:\\uva_in.txt", "r", stdin);
#endifwhile (scanf("%lu%lu%lu", &b, &p, &m) ==3) {
res=bigmod(b, p, m);
printf("%lu\n", res);
    }
return0;
}
unsignedlongbigmod(unsignedlongb, unsignedlongp, unsignedlongm) 
{
if (p==0)
return1;
elseif (p%2==0)
returnsquare(bigmod(b, p/2, m)) %m;
elsereturn (b%m) *bigmod(b, p-1, m) %m;
}
unsignedlongsquare(unsignedlonga)
{
returna*a;
}
目录
相关文章
Light oj 1080 - Binary Simulation(树状数组区间更新点查询)
有一字符串只包含0和1,然后又m组操作,I L R是将从L到R的字符进行翻转操作0变为1、1变为0,Q x表示询问第x的字符。
43 0
UVa343 What Base Is This
UVa343 What Base Is This
49 0
UVa11076 - Add Again
UVa11076 - Add Again
56 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
102 0
|
前端开发
HDOJ 1212 Big Number
HDOJ 1212 Big Number
112 0
HDOJ1018Big Number
HDOJ1018Big Number
109 0
|
机器学习/深度学习
POJ 1423 Big Number
POJ 1423 Big Number
103 0
Multi-Cloud for the Digital Silk Road?
In this blog, our guest writer Jamil Ahmed compares the performance of China's top 3 domestic cloud providers, namely Alibaba Cloud, Huawei Cloud, and Tencent Cloud.
1120 0