首页 > 其他分享 >UVa 374 Big Mod (快速幂取模)

UVa 374 Big Mod (快速幂取模)

时间:2023-04-12 13:03:24浏览次数:53  
标签:取模 integer int Big ans UVa problem mod


374 - Big Mod

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310

Calculate

for large values of BP, and M using an efficient algorithm. (That's right, this problem has a time dependency !!!.)

Input

Three integer values (in the order BPM) will be read one number per line. B and P are integers in the range 0 to 2147483647 inclusive. M is an integer in the range 1 to 46340 inclusive.

Output

The result of the computation. A single integer.

Sample Input

3
18132
17

17
1765
3

2374859
3029382
36123


Sample Output


13
2
13195



拿来复习下这个函数。。


完整代码:

/*0.012s*/

#include<cstdio>

int main()
{
	int b, p, mod, ans;
	while (~scanf("%d%d%d", &b, &p, &mod))
	{
		b %= mod;
		ans = 1;
		while (p)
		{
			if (p & 1)
				ans = ans * b % mod;
			b = b * b % mod;
			p >>= 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}



标签:取模,integer,int,Big,ans,UVa,problem,mod
From: https://blog.51cto.com/u_5535544/6185489

相关文章

  • UVa 112 Tree Summing (scanf()去空格&递归&二叉树遍历)
    112-TreeSummingTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=48BackgroundLISPwasoneoftheearliesthigh-levelprogramminglanguagesand,withFORTRAN,isoneoft......
  • UVa 10161 Ant on a Chessboard (简单数学)
    10161-AntonaChessboardTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1102Background  Oneday,anantcalledAlicecametoanM*Mchessboard.Shewan......
  • UVa 113 / POJ 2109 Power of Cryptography (使用double处理大整数&泰勒公式与误差分
    113-PowerofCryptographyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=49http://poj.org/problem?id=2109题意:给出n和p,求出 ,但是p可以很大()如何存储p?不用大数可不可以?先看看double......
  • UVa 457 Linear Cellular Automata (water ver.)
    457-LinearCellularAutomataTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=398AbiologistisexperimentingwithDNAmodificationofbacterialcolonies......
  • UVa 489 Hangman Judge (模拟&字符串匹配)
    489-HangmanJudgeTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=430In``HangmanJudge,''youaretowriteaprogramthatjudgesaseriesofH......
  • UVa 10783 Odd Sum (water ver.)
    10783-OddSumTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724Givenarange [a, b],youaretofindthesummationofalltheoddintegersinthisran......
  • UVa 524 Prime Ring Problem (数论&DFS)
    524-PrimeRingProblemTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=465Aringiscomposedofn(evennumber)circlesasshownindiagram.Putnaturalnumbers  intoea......
  • UVa 696 How Many Knights (想法题)
    696-HowManyKnightsTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=637Theknightisapieceusedinchess,agameplayedonaboardwithsquaresarrangedinrowsandcolumns.Aknight......
  • UVa 10785 The Mad Numerologist (排序)
    10785-TheMadNumerologistTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=1726Numerologyisasciencethatisusedbymanypeopletofindoutamansper......
  • UVa 10344 23 out of 5 (全排列枚举&回溯)
    10344-23outof5Timelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1285Yourtaskistowriteaprogramthatcandecidewhetheryoucanfindanarithmetic......