Codeforces Round #628 (Div. 2)

A. EhAb AnD gCd

You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x.
As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it.
It’s guaranteed that the solution always exists. If there are several such pairs (a,b), you can output any of them.

Input

The first line contains a single integer t (1≤t≤100) — the number of testcases.
Each testcase consists of one line containing a single integer, x (2≤x≤109).

Output

For each testcase, output a pair of positive integers a and b (1≤a,b≤109) such that GCD(a,b)+LCM(a,b)=x. It’s guaranteed that the solution always exists. If there are several such pairs (a,b), you can output any of them.

Example

input

2
2
14

output

1 1
6 4

题意:给定一个x,要求输出两个数a,b,使得gcd(a,b)+lcm(a,b)== x。

思路:水题,输出1和x-1即可。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
 
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int x;
        cin >> x;
        cout << 1 << " " << x-1 << endl;
    }
    return 0;
}

B. CopyCopyCopyCopyCopy

Ehab has an array a of length n. He has just enough free time to make a new array consisting of n copies of the old array, written back-to-back. What will be the length of the new array’s longest increasing subsequence?
A sequence a is a subsequence of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.

Input

The first line contains an integer t — the number of test cases you need to solve. The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤105) — the number of elements in the array a.
The second line contains n space-separated integers a1, a2, …, an (1≤ai≤109) — the elements of the array a.
The sum of n across the test cases doesn’t exceed 105
.

Output

For each testcase, output the length of the longest increasing subsequence of a if you concatenate it to itself n times.**

Example

input

2
3
3 2 1
6
3 1 4 1 5 9

output

3
5

题意:给定一个数组,可以改变顺序,求最大的递增子序列。

思路:排序,遍历一遍,s[i]>s[i-1],cnt++,输出cnt即可。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
 
int s[100010];
 
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++) cin >> s[i];
        sort(s,s+n);
        int cnt = 1;
        for(int i = 1; i < n; i++){
            if(s[i]>s[i-1]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值