[Codeforces Round #628]1325

1325A - EhAb AnD gCd[思维]
1325B - CopyCopyCopyCopyCopy[思维]
1325C - Ehab and Path-etic MEXs[思维][]
1325D - Ehab the Xorcist[思维+异或]
1325E - Ehab’s REAL Number Theory Problem[思维+最小环 d f s dfs dfs]
1325F - Ehab’s Last Theorem[ d f s dfs dfs树+独立集]


1325A - EhAb AnD gCd[思维]

time limit per testmemory limit per testinputoutput
1 seconds256 megabytesstandard inputstandard output

Description:

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

Input

The first line contains a single integer t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1t100) — the number of testcases.
Each testcase consists of one line containing a single integer, x ( 2 ≤ x ≤ 1 0 9 ) x (2≤x≤10^9) x(2x109).

Output

For each testcase, output a pair of positive integers a a a and b b b ( 1 ≤ a , b ≤ 1 0 9 ) (1≤a,b≤10^9) (1a,b109) such that G C D ( a , b ) + L C M ( a , b ) = x GCD(a,b)+LCM(a,b)=x GCD(a,b)+LCM(a,b)=x. It’s guaranteed that the solution always exists. If there are several such pairs ( a , b ) (a,b) (a,b), you can output any of them.


Example input

2
2
14

Example output

1 1
6 4


分析:
题意:
a , b a, b a,b使得 g c d ( a , b ) + l c m ( a , b ) = n gcd(a,b)+lcm(a,b) = n gcd(a,b)+lcm(a,b)=n
做法:
其实, g c d ( n , 1 ) = 1 , l c m ( n , 1 ) = n gcd(n, 1) = 1, lcm(n, 1) = n gcd(n,1)=1,lcm(n,1)=n
因此,答案就是 1 1 1 n − 1 n-1 n1


Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 5;

int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        printf("%d %d\n", 1, n-1);
    }
    return 0;
}


1325B - CopyCopyCopyCopyCopy[思维]

time limit per testmemory limit per testinputoutput
1 seconds256 megabytesstandard inputstandard output

Description:

Ehab has an array a of length n n n. He has just enough free time to make a new array consisting of n n 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 b 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 t 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 ≤ 1 0 5 ) n(1≤n≤10^5) n(1n105) — the number of elements in the array a a a.
The second line contains n space-separated integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 9 ) a_1, a_2, …, a_n (1≤a_i≤10^9) a1,a2,,an(1ai109) — the elements of the array a a a.

Output

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


Example input

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

Example output

3
5


分析:
题意:
给一个长度为 n n n的数组 a a a,数组 a a a可以整个长度 n n n一起复制一遍,问最后可以得到的最长递增序列长度为多少
做法:
只要统计出现的不同数字的个数


Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100 + 5;

map<int, int> mp;

int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        int n, x;
        scanf("%d", &n);
        mp.clear();
        for(int i = 1; i <= n; ++i) {
            scanf("%d", &x);
            mp[x] = 1;
        }
        printf("%d\n", mp.size());
    }
    return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值