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的字符。
49 0
UVa343 What Base Is This
UVa343 What Base Is This
67 0
UVa11076 - Add Again
UVa11076 - Add Again
63 0
UVa1584 - Circular Sequence
UVa1584 - Circular Sequence
46 0
|
人工智能 BI
UVa1554 - Binary Search
UVa1554 - Binary Search
56 0
|
机器学习/深度学习 网络架构
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree(一)
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree
122 0
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree(一)
|
机器学习/深度学习 网络架构
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree(二)
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree
134 0
Denodo For Big Data
In order to build Virtual Data Services, the user follows three simple steps: 1. Connect & Virtualize Any Source.
2304 0