(A1^B1+A2^B2+ ... +AH^BH)mod M.
2016-07-23 11:17
211 查看
- C
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%lld
& %llu
Submit Status
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 mathematical games. Latest marketing research shows, that this market segment
was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:
Each player chooses two 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 all expressions Ai Bi from all players
including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.
You should write a program that calculates the result and is able to find out who won the game.
Input
The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be
divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.
Output
For each assingnement there is the only one line of output. On this line, there is a number, the result of expression
取模公式(A1B1+A2B2+ ...
+AHBH)mod M.=(A1B1mod
M.+A2B2mod M.+...........AHBHmod
M.)mod M.
Sample Input
Sample Output
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
if(b%2==1)
t=t*a%c;
b=b/2;
a=a*a%c;
}
return t;//刚开始也总是忘记写,马马虎虎
}
int main()
{
int k,t,h,m,a[45000],b[45000];
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
scanf("%d",&h);
int sum=0;
for(int i=0;i<h;i++)
{
scanf("%d%d",&a[i],&b[i]);
sum=sum+f(a[i],b[i],m);
}
k=sum%m;
printf("%d\n",k);
}
return 0;
}
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%lld
& %llu
Submit Status
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 mathematical games. Latest marketing research shows, that this market segment
was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:
Each player chooses two 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 all expressions Ai Bi from all players
including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.
You should write a program that calculates the result and is able to find out who won the game.
Input
The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be
divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.
Output
For each assingnement there is the only one line of output. On this line, there is a number, the result of expression
取模公式(A1B1+A2B2+ ...
+AHBH)mod M.=(A1B1mod
M.+A2B2mod M.+...........AHBHmod
M.)mod M.
Sample Input
3 16 4 2 3 3 4 4 5 5 6 36123 1 2374859 3029382 17 1 3 18132
Sample Output
2 13195131
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h> int f(int a,int b,int c) { int t=1%c;
a=a%c;//一定要事先取余,总是忘记,哎。。while(b>0)
{
if(b%2==1)
t=t*a%c;
b=b/2;
a=a*a%c;
}
return t;//刚开始也总是忘记写,马马虎虎
}
int main()
{
int k,t,h,m,a[45000],b[45000];
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
scanf("%d",&h);
int sum=0;
for(int i=0;i<h;i++)
{
scanf("%d%d",&a[i],&b[i]);
sum=sum+f(a[i],b[i],m);
}
k=sum%m;
printf("%d\n",k);
}
return 0;
}
相关文章推荐
- Hibernate的相关概念 以及 序列化和持久化的区别
- bfc
- 常用mac 命令
- 利用@media screen实现网页布局的自适应
- 二叉树中和为某一值的路径
- java中的包
- 我的第一个MarkDown文档
- BFC特性
- Unix环境高级编程 centos中配置apue编译环境
- Core_2_图像操作
- 利用人体肤色从图像中分割出人体区域的OpenCV代码
- HDOJ-2035 人见人爱A^B
- 解决VM克隆虚拟机网络IP配置问题及时区改为中国时区
- Linux下用speedtest-cli测网速
- HDOJ-4883 TIANKENG’s restaurant
- Oracle Error:ORA-01465: 无效的十六进制数字【解决办法】
- jquery基础
- Gradle依赖的统一管理
- linux基础1
- 很不错的,推荐下——关于有偿提供拼图响应式后台的通知