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;
}
目录
相关文章
|
3月前
hdu 1019 Least Common Multiple
hdu 1019 Least Common Multiple
15 0
|
6月前
hdu 1019 Least Common Multiple
hdu 1019 Least Common Multiple
18 0
|
7月前
codeforces 344B - Simple Molecules
题意就是给出3个原子的化学价,然后组成一个分子,要保证这个分子是稳定的,如果你还记得高中化学知识的话这个很容易理解,然后让你求出1-2 2-3 1-3 号原子之间有几条键, 这里我分别用ta tb tc 表示, 用数学的方法表示出来的话就是a = tc + tb; b = ta+tc; c = ta + tb;可能有多种情况,只要输出一种即可。
21 0
|
9月前
UVa11565 - Simple Equations
UVa11565 - Simple Equations
35 0
|
9月前
UVa343 What Base Is This
UVa343 What Base Is This
34 0
|
机器学习/深度学习
POJ 1423 Big Number
POJ 1423 Big Number
83 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)$ 然后又有两种情况。
1149 0