The first training game of the Niu guest in winter vacation

Contest link
problem to solve
B problem
Construction problem
First find a more efficient way to construct brackets
(()) This kind of brackets is more efficient and legal,
so the idea is to square the given integer, and the remaining fractions we use enumeration method .
But for some data directly constructed with the number x obtained by the square root , it will cause the fraction to be too small, and it is not easy to construct the fraction. The
first step is to construct a symmetrical parenthesis with x left parentheses. If the fraction is less than x , it will not Good structure. So if the fraction is less than x , choose to reduce x by 1 , and then construct the fraction.
code show as below

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string> 
#include<cmath>
using namespace std;
typedef long long ll;
const int Max = 5000;
ll n, k;
int p[Max],v[Max],cnt;
void xxs()
{
    
    
	for(int i = 2; i <= Max; ++i)
	{
    
    
		if(!v[i]) p[cnt++] = i;
		for(int j = 0; p[j] * i < Max; ++j)
		{
    
    
			if(p[j] * i < Max) v[p[j] * i] = 1;
			if(i % p[j] == 0) break;
		}
	}
}
void work()
{
    
    
	if(k == 0) {
    
    
		cout << ")(" << endl;return ;
	}
	ll x = (int)sqrt(k);
	
	ll sum = k - x * x;
	ll a = sum - x;
	if(a <= 0) 
	{
    
    
		x--;
		sum = k - x * x;
		a = sum - x;
	}
	for(ll i = 1; i <= x; i++) printf("(");
	for(ll i = 1; i <= x; i++) printf(")");
	for(ll i = 1; i <= a; ++i) printf("(");
	printf(")");
	cout << endl;
}
int main()
{
    
    
	cin >> k;
	work();
    return 0;
}

Question I
is also a construction question.
First observe the data range
. The logarithm required to be constructed is less than n/2, which can be associated with the construction of odd and even numbers.
Insert picture description here
Since n even numbers can only construct n-1 pairs,
there are two cases k<=n/2 and k == n/2;
secondly, in the second case, we have to use multiples of 3 to construct (the even construction is actually Use multiples of 2, if k has no limit, you can also use multiples of 5, etc., that is, multiples of prime factors to construct), and use a multiple of 3 to construct, you can take 6 out, because 6 is also 2 Multiples and is the smallest of 2 and 3 multiples at the same time.

#include<bits/stdc++.h>
using namespace std;
int n,k;
int main()
{
    
    
	cin >> n >> k;
	if(k < n / 2)
	{
    
    
		for(int i = 1; i <= k + 1; ++i) 
			printf("%d ", i * 2);
		for(int i = 1; i <= k + 1; ++i)
			printf("%d ", i * 2 - 1);
		for(int i = 2 * k + 3; i <= n; ++i)
			printf("%d ", i);
	}
	else 
	{
    
    
		if(n < 6) {
    
    
			printf("-1");return 0;
		}
		for(int i = 1; i <= k; ++i)
			if(i * 2 != 6) printf("%d ", i * 2);
		printf("6 3 ");
		for(int i = 1; i <= n; i += 2)
			if( i != 3) printf("%d ", i);
		//for(int i = 1; i <= n; ++i)
		//	if( i*2-1 != 3) printf("%d ", i * 2 - 1);
		// if(n % 2 != 0) printf("%d",n);
		// 这个输出方式很容易忽略掉最后一个n导致出错,如果是奇数,n不会输出,所以要打个补丁
	}
	return 0;
}

The
Insert picture description here
biggest prime factor of the J question is to satisfy 2 * Pi (one power) <= n / 2
The LCM for finding the remaining number is based on the
unique decomposition theorem
2 * 2 * 2 * 3 * 3 and 2 * 2 * 3 * 3 * 3 The LCM
of these two numbers is the product of the highest power of 2 and the highest power of 3.
The LCM of n numbers is the conclusion in the figure.

#include<bits/stdc++.h>
using namespace std;
#define N 80010000
#define ll long long
int num[N], prim[5000060];
int pn = 0;
const ll mod = 1e9 + 7;
void table()
{
    
    
    memset(num, -1, sizeof(num));
    for(int i = 2; i < N; i++)
    {
    
    
        if(num[i]) prim[pn++] = i;
        for(int j = 0; j < pn && 1LL*i*prim[j] < N; j++)
        {
    
    
            num[i*prim[j]] = 0;
            if(i % prim[j] == 0) break;
        }
    }
}
int main()
{
    
    
    table();
    ll res = 1, i, n;
    cin >> n;
    if(n < 6) {
    
    cout << "empty";return 0;}
    for(i = 1; prim[i] <= n / 2; i++)//  从质数3开始遍历求直到 Pi
    {
    
    
        ll p = prim[i], temp = 1;
        
        while(temp * p <= n / 2) temp *= p;// 要让k最大,那么就要乘以最小的质数2
        								//因为我们只需要求每个质数的最高次幂
        
        res = res * temp % mod;
    }
    ll temp2 = 1;
    while(temp2 * 2 <= n / 3) temp2 *= 2; // 单独求一下2的最高次方
    res = res * temp2 % mod;
    cout << res;
}

Guess you like

Origin blog.csdn.net/cosx_/article/details/113562853