Codeforces Round #716 (Div. 2) (位运算AND)
B. AND 0, Sum Big
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Baby Badawy’s first words were “AND 0 SUM BIG”, so he decided to solve the following problem. Given two integers n and k, count the number of arrays of length n such that:
all its elements are integers between 0 and 2k?1 (inclusive);
the bitwise AND of all its elements is 0;
the sum of its elements is as large as possible.
Since the answer can be very large, print its remainder when divided by 109+7.
Input
The first line contains an integer t (1≤t≤10) — the number of test cases you need to solve.
Each test case consists of a line containing two integers n and k (1≤n≤105, 1≤k≤20).
Output
For each test case, print the number of arrays satisfying the conditions. Since the answer can be very large, print its remainder when divided by 109+7.
Example
inputCopy
2
2 2
100000 20
outputCopy
4
226732710
Note
In the first example, the 4 arrays are:
[3,0],
[0,3],
[1,2],
[2,1].
C. Product 1 Modulo N
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Now you get Baby Ehab’s first words: “Given an integer n, find the longest subsequence of [1,2,…,n?1] whose product is 1 modulo n.” Please solve the problem.
A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly all) elements. The product of an empty subsequence is equal to 1.
Input
The only line contains the integer n (2≤n≤105).
Output
The first line should contain a single integer, the length of the longest subsequence.
The second line should contain the elements of the subsequence, in increasing order.
If there are multiple solutions, you can print any.
Examples
inputCopy
5
outputCopy
3
1 2 3
inputCopy
8
outputCopy
4
1 3 5 7
Note
In the first example, the product of the elements is 6 which is congruent to 1 modulo 5. The only longer subsequence is [1,2,3,4]. Its product is 24 which is congruent to 4 modulo 5. Hence, the answer is [1,2,3].
只能選與n互質的數,
設s為所有與n互質的數的積對n取模的結果,
如果s=1,那么這些數全部可以選擇,
如果s!=1,此時s一定與n互質,因此s也在這些數中,
那么選除了s的其他數就行了.
總結
以上是生活随笔為你收集整理的Codeforces Round #716 (Div. 2) (位运算AND)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STL常用工具集
- 下一篇: Codeforces Round #71