Raising Modulo Numbers
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 6347 |
|
Accepted: 3740 |
Description
People is different. Some secretly read magazines full of interesting girls ' pictures, others create a a-bomb in their cellar, others like USI Ng Windows, and some like difficult mathematical games. Latest Marketing the shows, that's the market segment were so far underestimated and that there are lack of such games. This kind of game is thus included into the Kokodákh. The rules follow:
Each player chooses the numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of any expressions Aibi from all players including oneself and determine the remainder AF ter division by a given number M. The winner is the one who first determines the correct result. According to the players ' experience it's possible to increase the difficulty by choosing higher numbers.
You should write a program that calculates the result and are able to find out who won the game.
Input
The input consists of Z assignments. The number of them is given by the "positive" integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing a integer M (1 <= M <= 45000). The sum is divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On all line, there is exactly, numbers Ai and Bi separated by space. Both numbers cannot is equal zero at the same time.
Output
For each assingnement there are the only one line of output. On this line, there is a number, the result of expression
(A1B1+A2B2+ ... +AHBH)mod M.
Sample Input
31642 33 44 55 63612312374859 30293821713 18132
Sample Output
21319513
Source
CTU Open 1999 ————————————— I'm a split line ———————————————————— quick power naked question
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <queue>7#include <cstdlib>8#include <iomanip>9#include <cassert>Ten#include <climits> One #defineMAXN 50001 A #defineF (i,j,k) for (int i=j;i<=k;i++) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (int i=j;i>=k;i--) the #defineINF 0x7fffffff - #defineP 23333333333333333 - using namespacestd; - intRead () { + intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} + while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} A returnx*F; at } - intm,h; - Long Longans; - Long LongKuaisumi (Long LongALong LongN) - { - Long Longans=1; in while(n) { - if(n&1) ans= (ans*a)%m; toA= (a*a)%m; +n>>=1; - } the returnans; * } $ intMain ()Panax Notoginseng { - intT; theCin>>T; + while(t--){ Aans=0; theCin>>m>>h; + for(intI=0; i) - { $ Long Longb; $Cin>>a>>b; -Ans= (Ans+kuaisumi (b))%m; - } thecout<<ans<<Endl; - } Wuyi return 0; the}
View Code
POJ 1995 Raising Modulo Numbers