Jiamusi Training Day3 Exam

Tucao the first two questions of today’s exam, the correct solution is not as high as violence...or rk1...
Insert picture description here

String

Title description
Given two strings of equal length, ensure that there is an odd number of differences between the strings, and request the number of strings in the middle of therow.
Enter the
first line, a positive integer n represents the length of the string and the
next 2 lines, which means two A string of length n is
output in
one line, representing the string in the middle
sample input
2
az
bf
sample output
bc

Set a to 0, b to 1, c to 2...z to 25.
Add the two strings in the 26 base and divide by 2 is fine.
Note that the addition is carried and divided by 2 to return one bit Otherwise you will lose 60 points

#include<cstdio>
int n,a[200010],b[200010],c[200020];
char ch;
int main()
{
    
    
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
    
    
		ch=getchar();
		while(ch<'a'||ch>'z')ch=getchar();
		a[n-i+1]=ch-'a';
	}
	for(int i=1;i<=n;i++)
	{
    
    
		ch=getchar();
		while(ch<'a'||ch>'z')ch=getchar();
		b[n-i+1]=ch-'a';
	}
	for(int i=1;i<=n;i++)
	{
    
    
		c[i]+=a[i]+b[i];
		c[i+1]+=(c[i]/26);
		c[i]%=26;
	}
	bool bl=0;
	if(c[n+1]>0)
	{
    
    
		n++;
		bl=1;
	}
	for(int i=n;i;i--)
	{
    
    
		c[i-1]+=(c[i]%2*26);
		c[i]/=2;
	}
	if(bl)n--;
	for(int i=n;i;i--)putchar(c[i]+'a');
	putchar('\n');
}

gcd

Title description
Given n numbers, ask at least a few numbers, so that their gcd is 1.
Input the
first line a positive integer n the
second line, a total of n numbers means ai
output and
output 1 line, which means the answer, if it does not exist Then output -1
Sample input
3
10 6 15
Sample output
3
Data range
For 40% guarantee n<=20
For another 20% guarantee n<=1000, ai<=2000
For 100% guarantee 1<=n,ai< =300000

First of all, if you choose a number and this number does not reduce the prime factor of gcd, then this number is useless
and the maximum can only be 2 × 3 × 5 × 7 × 11 × 13 × 17 = 510510 > 300000 2×3× 5×7×11×13×17=510510>3000002×3×5×7×11×13×17=510510>3 0 0 0 0 0 7 prime factors, so the answer must be less than or equal to 7,
so we can judge whether the total gcd outputs -1 when inputting, and then in 1-7,
the basicideaof the randnumber problem ismy ownthinking: Enumgcd gcdgcd
f ( i ) f(i) f ( i ) is the current selectionkkWhen the number of k iskkThe common divisor of k numbers is the total scheme of i,
letg (i) g(i)g ( i ) is currently selectedkkWhen the number of k iskkk numbermaximumThe general scheme with the common divisor i,
then g (i) = f (i) − ∑ j = 2 ⌊ nj ⌋ f (i ∗ j) g(i)=f(i)-\sum_{j=2}^{ \left \lfloor \frac{n} {j} \right \rfloor}f(i*j)g(i)=f(i)j=2jnf(ij )
fromnnn to1 11 Requestg (i) g (i)g ( i ) and finally ifg (1) g(1)g ( 1 ) is greater than0 00 Zekkk is a legal answer,
so you must have a problemf (i) f(i)How to find f ( i ) ? Good question
f (i) f(i)f ( i ) To select the total plan with k number common divisor i, we need to preprocess the number sequence to beiii multiples ofcnt (i) cnt (i)cnt(i)
显然 f ( i ) = ( c n t ( i ) k ) f(i)=\binom{cnt(i)}{k} f(i)=(kcnt(i))
So we need to preprocess1 − N 1-N1N 's factorial inversemod modm O D random prime number is provided a little large enoughset smaller you kneeling
time complexity isO (n ln ⁡ n) OO ( nlnn ) The
code is as follows

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=300010,mod=1000000009;
inline void read(int &x)
{
    
    
	int s=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
    
    s=(s<<3)+(s<<1)+(ch&15);ch=getchar();}
	x=s;
}
ll inv[N],fac[N],facinv[N],f[N];
ll C(ll n, ll m){
    
    return !n?0:fac[n]*facinv[m]%mod*facinv[n-m]%mod;}
int n,x,cnt[N];
bool check(int l)
{
    
    
	memset(f,0,sizeof(f));
	for(int i=N-1;i;i--)
	{
    
    
		f[i]=C(cnt[i],l);
		if(f[i])for(int j=2;i*j<N;j++)f[i]=(f[i]-f[i*j]+mod)%mod;
	}
	return f[1];
}
int main()
{
    
    
	fac[0]=facinv[0]=inv[1]=fac[1]=facinv[1]=1;
	for(int i=2;i<=N;i++)
	{
    
    
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fac[i]=fac[i-1]*i%mod;
		facinv[i]=facinv[i-1]*inv[i]%mod;
	}
	read(n);
	for(int i=1;i<=n;i++)
	{
    
    
		read(x);
		cnt[x]++;
	}
	for(int i=1;i<N;i++)
	{
    
    
		for(int j=2;j*i<N;j++)cnt[i]+=cnt[i*j];
	}
	x=1;
	while(!check(x)&&x<=7)x++;
	if(x>7)puts("-1");
	else printf("%d\n",x);
}

T3 Mo team due to D awn DawnD a w n is toodelicious,so I gave up. If you
have any questions, you can write to the comment area below or addQQ 407694747 QQ407694747Q Q 4 0 7 6 9 4 7 4 7 we discuss together
the brightest god you big brother Ben exhibitions

Guess you like

Origin blog.csdn.net/dhdhdhx/article/details/97618149