码迷,mamicode.com
首页 > 其他好文 > 详细

【TOJ 1723】Just calculate it!

时间:2018-05-05 23:05:39      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:turn   images   panel   lease   XA   mod   AC   The   nes   

描述

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 1723】Just calculate it!

标签:turn   images   panel   lease   XA   mod   AC   The   nes   

原文地址:https://www.cnblogs.com/kannyi/p/8996444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!