牛客练习赛111(2023.5.5)位运算、分类讨论、数论分块、贝祖定理&扩展欧几里得

147 阅读1分钟

A 题

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int ,int > PII;
const int N = 2e5+3,null=0x3f3f3f3f;
int n;
int main(){
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		int tmp=x;
		int cnt=0;
		while(tmp>0){
			if(tmp%10==0){
				tmp/=10;
				cnt++;
			}
			else{
				break;
			}
		}
		int res=(int)pow(10,cnt+1)-(x%(int)pow(10,cnt+1));
		cout<<res<<endl;
	
	}
} 

B 题

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int ,int > PII;
const int N = 2e5+3,null=0x3f3f3f3f;
int n;
int main(){
	cin>>n;
	char c1[N];
	char c2[N];
	scanf("%s",c1);
	scanf("%s",c2);
	int res[N];
	memset(res,-1,sizeof(res));
	int cnt=0;
	int flag=0;
	int s[26];
	for(int i=0;i<n;i++){
		s[c1[i]-'a']++;
		if(s[c1[i]-'a']>1)
		flag=1;
		if(c1[i]!=c2[i]){
			res[cnt++]=i;
		}
	}
	if(cnt==0&&flag)
	cout<<"YES"<<endl;
	else if(c1[res[0]]==c2[res[1]]&&c1[res[1]]==c2[res[0]]&&cnt==2)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
} 

C 题

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int ,int > PII;
const int N = 2e5+3,null=0x3f3f3f3f;
int n;
int main(){
	cin>>n;
	while(n--){
		int m,x;
		cin>>m>>x;
		int tmp=m/x;
		cout<<m/tmp-m/(tmp+1)<<endl;
	}
} 

D 题

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = 1e9;

int exgcd(int a, int b, int &x, int &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }

    int d = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

void solve() {
    int a, b, n, L, R;
    cin >> a >> b >> n >> L >> R;

    int x, y;
    int d = exgcd(a, b, x, y);

    if (n % d != 0) {
        puts("NO");
        return ;
    }

    int p = b / d;
    x = (LL)x * n / d % p;
    x = (x % p + p) % p;

    int l, r;

    if (L - x < 0)
        l = 0;
    else
        l = (L - x + p - 1) / p;

    if (R - x < 0)
        r = -1;
    else
        r = (R - x) / p;

    if (l > r)
        puts("NO");
    else
        puts("YES");
}
int main() {
    //  freopen("a.txt","r",stdin);

    int T = 1;
    cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}