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;
}
目录
相关文章
|
4月前
hdu 1019 Least Common Multiple
hdu 1019 Least Common Multiple
24 0
|
10月前
hdu 1019 Least Common Multiple
hdu 1019 Least Common Multiple
25 0
UVa343 What Base Is This
UVa343 What Base Is This
43 0
|
机器学习/深度学习
POJ 1423 Big Number
POJ 1423 Big Number
94 0
|
人工智能
poj2356:Find a multiple
题目链接: 【鸽巢原理+乱搞】 其实用不着开$map$ 一步最巧妙的转化是$……$前缀和。 反正本宝宝突发奇想就出来了。 首先,我们分类讨论。 1.当$∃i \in N_{+} $ 且 $i \in [1,n]$ 使 $a_{i} | n$ 则直接选这个数就好 2.没有以上那种特殊情况的话,我们记录前缀和$sum_{i}= \sum _{k=1}^{i} a_{k} (mod \ \ n)$ 然后又有两种情况。
1171 0