CF round 236 div1

3 篇文章 0 订阅
3 篇文章 0 订阅


A. Searching for Graph
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:

  • the graph contains exactly 2n + p edges;
  • the graph doesn't contain self-loops and multiple edges;
  • for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges.

subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.

Your task is to find a p-interesting graph consisting of n vertices.

Input

The first line contains a single integer t (1 ≤ t ≤ 5) — the number of tests in the input. Next t lines each contains two space-separated integers: np (5 ≤ n ≤ 24p ≥ 0) — the number of vertices in the graph and the interest value for the appropriate test.

It is guaranteed that the required graph exists.

Output

For each of the t tests print 2n + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers ai, bi (1 ≤ ai, bi ≤ nai ≠ bi) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to n.

Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them.

Sample test(s)
input
1
6 0
output
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6

B. Upgrading Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have an array of positive integers a[1], a[2], ..., a[n] and a set of bad prime numbers b1, b2, ..., bm. The prime numbers that do not occur in the set b are considered good. The beauty of array a is the sum , where function f(s) is determined as follows:

  • f(1) = 0;
  • Let's assume that p is the minimum prime divisor of s. If p is a good prime, then , otherwise .

You are allowed to perform an arbitrary (probably zero) number of operations to improve array a. The operation of improvement is the following sequence of actions:

  • Choose some number r (1 ≤ r ≤ n) and calculate the value g = GCD(a[1], a[2], ..., a[r]).
  • Apply the assignments: ....

What is the maximum beauty of the array you can get?

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 5000) showing how many numbers are in the array and how many bad prime numbers there are.

The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — array a. The third line contains m space-separated integers b1, b2, ..., bm (2 ≤ b1 < b2 < ... < bm ≤ 109) — the set of bad prime numbers.

Output

Print a single integer — the answer to the problem.

Sample test(s)
input
5 2
4 20 34 10 10
2 5
output
-2
input
4 5
2 4 8 16
3 5 7 11 17
output
10

D. Beautiful Pairs of Numbers
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The sequence of integer pairs (a1, b1), (a2, b2), ..., (ak, bk) is beautiful, if the following statements are fulfilled:

  • 1 ≤ a1 ≤ b1 < a2 ≤ b2 < ... < ak ≤ bk ≤ n, where n is a given positive integer;
  • all numbers b1 - a1b2 - a2...bk - ak are distinct.

For the given number n find the number of beautiful sequences of length k. As the answer can be rather large, print the remainder after dividing it by 1000000007 (109 + 7).

Input

The first line contains integer t (1 ≤ t ≤  2·105) — the number of the test data.

Each of the next t lines contains two integers n and k (1 ≤ k ≤ n ≤ 1000).

Output

For each test from the input print the answer to the problem modulo 1000000007 (109 + 7). Print the answers to the tests in the order in which the tests are given in the input.

Sample test(s)
input
6
1 1
2 1
2 2
3 1
3 2
3 3
output
1
3
0
6
2
0
Note

In the first test sample there is exactly one beautiful sequence: (1, 1).

In the second test sample, the following sequences are beautiful:

  • (1, 1);
  • (1, 2);
  • (2, 2).

In the fourth test sample, the following sequences are beautiful:

  • (1, 1);
  • (1, 2);
  • (1, 3);
  • (2, 2);
  • (2, 3);
  • (3, 3).

In the fifth test sample, the following sequences are beautiful:

  • (1, 1), (2, 3);
  • (1, 2), (3, 3).

In the third and sixth samples, there are no beautiful sequences.



1 最讨厌构造题了,思维弱了。。。。
我是从2*n + p的角度考虑的。。首先要把2*n构造出了。恩,可以1->2, 1->3, 2->3, 2->4, ..., n->1, n->2
这样构造。。。容易证明这样构造是正确的。。
证明略


2 f函数的计算 n = p1^a1*p2^a2*...*pn^an, 不妨设p1, p2 是bad prime
则f(n) = a1 + a2 - sigma(ai, i >= 3)
然后预处理出前缀的最大公约数.
对于最大公约数这个操作,显然是从右向左的。。。。证明略
不妨设最优解为p1 > p2 >....>pn
ans = sigma(f(i))
下面我们采用贪心策略从最右端开始贪心,如果f(g[i])小于0,则保留这种操作,否则继续。。
不妨设得到的序列为p1' > p2'>...>pn'
首先我们证明p1 == p1'
显然p1 <= p1'
如果p1' > p1 则可以构造如下一个更优的解p1' > p1 > p2 >...>pn
所以p1' = p1, 后面证明类似.
后面的题目等会补上......

3 该题比较easy吧,注意到存在aii > 0 说明存在一个自环, 首先如果存在k 使得a^k(i, j)大于0,说明i 到 j 是可达的,
同理 j 到 i 也是可达的,所以该图是一个强联通图,下面我们来证明一下如果该图是强联通图,必然存在一个足够大的K使得
对于任意i, j a^k(i, j) > 0 。。。。这个也是比较好证明的,可利用自环的性质多走几步。。。。。故成立


4 个人觉得本题和2题算是相对比较困难的题目,我这题想了很久。。。。
  这里引用David Hilbert的一句话,人们往往不能解决一个问题的原因是不知道换一种方式来描述这个问题。
  首先拿到这个题我就被1 <= a1 <= b1 < a2 <= b2 <...<an = bn <= n这个条件困住了。。。。

  然后看了题解。。。。。。。。(想了N久)
  其实可以看成一系列互不相交的区间...
  [ ------  -------  ------ ]
  区间的左右端点分别为0, n + 1
  故该问题等价于
  x1 + x2 + ... + x(k+1) = n + 1 - len的正整数解的个数..
  c(n-len, k) 知道这一点就比较好做了.....
 










  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值