Codeforces Round #511 (Div. 2) A、B、C

A:

Little C Loves 3 I

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little C loves number «3» very much. He loves all things about it.

Now he has a positive integer nn. He wants to split nn into 33 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 33 integers is a multiple of 33. Help him to find a solution.

Input

A single line containing one integer nn (3≤n≤1093≤n≤109) — the integer Little C has.

Output

Print 33 positive integers a,b,ca,b,c in a single line, such that a+b+c=na+b+c=n and none of them is a multiple of 33.

It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

Examples

Input

Copy

3

Output

Copy

1 1 1

Input

Copy

233

Output

Copy

77 77 79

思路:

题目大意就是把一个正整数n分成三个正整数使得分得的三个数都不能整除3,既然对分割的数没什么要求,那就直接特判余0,1,2就行了

代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = (int)1e9 + 7;
int main()
{
    int n;
    scanf("%d",&n);
    if (n % 3 == 2)
        printf("1 2 %d\n",n - 3);
    else
        printf("1 1 %d\n",n - 2);
    return 0;
}

B:

Cover Points

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn points on the plane, (x1,y1),(x2,y2),…,(xn,yn)(x1,y1),(x2,y2),…,(xn,yn).

You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.

Input

First line contains one integer nn (1≤n≤1051≤n≤105).

Each of the next nn lines contains two integers xixi and yiyi (1≤xi,yi≤1091≤xi,yi≤109).

Output

Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.

Examples

Input

Copy

3
1 1
1 2
2 1

Output

Copy

3

Input

Copy

4
1 1
1 2
2 1
2 2

Output

Copy

4

Note

Illustration for the first example:

Illustration for the second example:

思路:

我们可以发现对于一个点能恰好覆盖住它的三角形的边长是x + y,所以只需要输出最小的x + y即可

代码:

#include<bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int main()
{
    int n,x,y,m = 0;
    scanf("%d",&n);
    for (int i = 0;i < n;i ++)
    {
        scanf("%d %d",&x,&y);
        m = max(m,x + y);
    }
    printf("%d\n",m);
    return 0;
}

C:

Enlarge GCD

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Mr. F has nn positive integers, a1,a2,…,ana1,a2,…,an .

He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers.

But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward.

Your task is to calculate the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.

Input

The first line contains an integer nn (2≤n≤3⋅1052≤n≤3⋅105 ) — the number of integers Mr. F has.

The second line contains nn integers, a1,a2,…,ana1,a2,…,an (1≤ai≤1.5⋅1071≤ai≤1.5⋅107 ).

Output

Print an integer — the minimum number of integers you need to remove so that the greatest common divisor of the remaining integers is bigger than that of all integers.

You should not remove all of the integers.

If there is no solution, print «-1» (without quotes).

Examples

Input

Copy

3
1 2 4

Output

Copy

1

Input

Copy

4
6 9 15 30

Output

Copy

2

Input

Copy

3
1 1 1

Output

Copy

-1

Note

In the first example, the greatest common divisor is 1 in the beginning. You can remove 1 so that the greatest common divisor is enlarged to 2 . The answer is 1 .

In the second example, the greatest common divisor is 33 in the beginning. You can remove 66 and 99 so that the greatest common divisor is enlarged to 15 . There is no solution which removes only one integer. So the answer is 2 .

In the third example, there is no solution to enlarge the greatest common divisor. So the answer is −1 .

思路:

题意大致是对于一堆数输出使得他们的gcd变大的最少的删除个数

我们让每个数初一他们的gcd,这样这道题就变成了除掉最少的数使gcd不等于1

那么我们统计它们公共质因子的个数,公共质因子个数越多,则删除的个数越少,再用n减去即可

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5 + 10;
const int Maxn = (int)1.5e7;
const int N = 4000;
bool check[N + 10];
int a[maxn],prime[1000],mp[Maxn + 10];
int pos = 0;
void init()
{
    for (int i = 2;i <= N;i ++)
    {
        if (!check[i])
        {
            prime[pos ++] = i;
            for (int j = i;j <= N;j += i)
                check[j] = 1;
        }
    }
}
void fac(int x)
{
    for (int i = 0;i < pos;i ++)
    {
        if (x % prime[i] == 0)
        {
            mp[prime[i]] ++;
            while (x % prime[i] == 0)
                x /= prime[i];
        }
    }
    if (x != 1)
        mp[x] ++;
}
int gcd(int a,int b)
{
    return b ? gcd(b,a % b) : a;
}
int main()
{
    memset(check,0,sizeof(check));
    memset(mp,0,sizeof(mp));
    init();
    int n,m;
    scanf("%d %d",&n,&a[0]);
    m = a[0];
    for (int i = 1;i < n;i ++)
    {
        scanf("%d",&a[i]);
        m = gcd(m,a[i]);
    }
    for (int i = 0;i < n;i ++)
    {
        a[i] /= m;
        fac(a[i]);
    }
    int ans = (int)1e8;
    for (int i = 1;i <= Maxn;i ++)
        if (mp[i])
            ans = min(n - mp[i],ans);
    printf("%d\n",(ans < n) ? ans : -1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/cloudy_happy/article/details/82815312