TOJ 1723Just calculate it!
Posted kannyi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TOJ 1723Just calculate it!相关的知识,希望对你有一定的参考价值。
描述
Given n positive numbers a1, a2, ..., an,two number m and b,please calculate the following expression:
Here "x mod y" is the positive remainder when x is divided by y. For example, 3 mod 7 = 3
输入
There are multiple test cases. Each teat case has two lines, the first line contains three positve integers n, m and b, the second line has n positive integers
a1, a2, ..., an a integer n, all positve numbers in this problem are not larger than 1000.
The end of input is marked by end of file.
输出
For each input, you should calculate value of the expression and output it.
样例输入
1 1 2
1
3 2 5
2 2 2
样例输出
1
2
#include<bits/stdc++.h> using namespace std; int main() { int n,m,b,i,j,a[1005]; //cifang-m mod-b while(scanf("%d%d%d",&n,&m,&b)!=EOF) { long long s=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); long long x=1; for(j=1;j<=m;j++) { x=x*a[i]; if(x>=b) x=x%b; } s=s+x; if(s>=b) s=s%b; } printf("%lld\n",s); } return 0; }
以上是关于TOJ 1723Just calculate it!的主要内容,如果未能解决你的问题,请参考以下文章