C - Raising Modulo Numbers (POJ - 1995)

- 题目大意

给出数字,求解(A1B1+A2B2+ ... +AHBH)mod M.

- 解题思路

简单的快速幂问题,套模板就行了。

- 代码

#include<iostream>

using namespace std;

long long powMod(long long a, long long n, long long p)
{
	long long ans = 1;
	for (; n > 0; n >>= 1)
	{
		if (n & 1)
			ans = ans * a%p;
		a = a * a%p;
	}
	return ans;
}
int main()
{
	int t, n, m, a, b;

	cin >> t;
	while (t--)
	{
		cin >> m >> n;
		long long sum = 0;
		while (n--)
		{
			cin >> a >> b;
			long long sum1 = powMod(a, b, m);
			sum = (sum + sum1) % m;
		}
		cout << sum << endl;
	}
}

  

原文地址:https://www.cnblogs.com/alpacadh/p/8448340.html

时间: 2024-08-29 10:32:44

C - Raising Modulo Numbers (POJ - 1995)的相关文章

Raising Modulo Numbers POJ 1995(快速幂模板)

原题 题目链接 题目分析 快速幂模板题,依题意套个求模快速幂,然后答案边加边模即可. 代码 1 #include <cstdio> 2 #include <cstdlib> 3 #include <iostream> 4 #include <algorithm> 5 #include <utility> 6 #include <ctime> 7 #include <cmath> 8 #include <cstring

POJ 1995 Raising Modulo Numbers (快速幂模板)

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4938   Accepted: 2864 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

POJ 1995 Raising Modulo Numbers (数论-整数快速幂)

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4379   Accepted: 2516 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

Raising Modulo Numbers(POJ 1995 快速幂)

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5934   Accepted: 3461 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

poj 1995 Raising Modulo Numbers

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4987   Accepted: 2887 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

poj 1995 Raising Modulo Numbers 题解

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6347   Accepted: 3740 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

poj Raising Modulo Numbers 快速幂模板

Raising Modulo Numbers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8606   Accepted: 5253 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, oth

Raising Modulo Numbers 取模+快速幂

Raising Modulo Numbers 题目地址:http://poj.org/problem?id=1995 Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult

POJ1995 Raising Modulo Numbers(快速幂)

POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时01分45秒 星期三 * Author: Akrusher * */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #