A:最低位
Given an positive integer A (1 <= A <= 100), output the lowest bit of A.
For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2.
Another example goes like this: given A = 88, we can write A in binary form as 1011000, so the lowest bit of A is 1000, so the output should be 8.
Input
Each line of input contains only an integer A (1 <= A <= 100). A line containing "0" indicates the end of input, and this line is not a part of the input data.
Output
For each A in the input, output a line containing only its lowest bit.
Sample Input
26
88
0
Sample Output
2
8
本题即求化为二进制下第一个1;而十进制化为二进制是不断取余二得到的,我们只需记录下取余了n次得到第一个一,而答案即是2的n次方。
C:麦哲伦的异或
MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (AiAi
+AjAj
)(1≤i,j≤n1≤i,j≤n
)
The xor of an array B is defined as B1B1
xor B2B2
…xor BnBn
Input
Multiple test cases, the first line contains an integer T(no more than 20), indicating the number of cases.
Each test case contains four integers:nn,mm,zz,ll,A1=0A1=0,Ai=(Ai−1∗m+z)Ai=(Ai−1∗m+z) modmod ll
1≤m,z,l≤5∗1051≤m,z,l≤5∗105,n=5∗105n=5∗105
output
For every test.print the answer.
Sample Input
2
3 5 5 7
6 8 8 9
Sample Output
14
16
该题想得到所有Bi异或的结果,而Bi是由Ai+Aj得到的。
,因为已经起始A0的值,再由输入的数据可以得到Ai 的值,最后将所得B异或得到最终答案。
因为A的值很多则表示A的数组需要在主函数外定义,以免栈溢出。
D:a的b次方
给你两个数A和B,计算A的B次方,输出A的B次方的最后三位数所表示的整数。
Input输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。Output对于每个测试实例,请输出A^B的最后三位表示的整数,每个输出占一行。
Sample Input
2 3
12 6
6789 10000
0 0
Sample Output
8
984
1
题目简单明了,求出数值以后取余1000即可。
但由于数值特别大需要使用快速幂。
E:取模运算
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.
Sample Input
3
16
4
2 3
3 4
4 5
5 6
36123
1
2374859 3029382
17
1
3 18132
Sample Output
2
13195
13
给出取模的值m,后给出h对数据a,b,求出a的b次幂取模求和即可。用快速幂即可,因为数据可能溢出,则在快速幂的时候就进行取模。
快速幂模板:
ll quickPow(ll x, ll n)
{
ll res = 1;
while (n > 0)
{
if (n & 1) res =(res* x)%1000;
x =(x* x)%1000;
n =(n>> 1);
}
return res;
}
该模板对数值取模了1000;