CodeCraft-21 and Codeforces Round #711 (Div. 2)

CodeCraft-21 and Codeforces Round #711 (Div. 2)

题号 题目 考点
A GCD Sum 签到,模拟
B Box Fitting 贪心
C Planar Reflections 规律+暴力(直接乱搞就对了)
D Bananas in a Microwave 思维题,贪心
E Two Houses
F https://blog.csdn.net/qq_35975367/article/details/115426186 博弈论,换根

A GCD Sum

A题过太久了,记不清了,反正直接模拟做就行了

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);
   return s*w;
}
#define MAXN 100005
#define MAXL 1299710
int prime[MAXN];
int tag[MAXL];
int tot = 0;
void Prime(int N){
	memset(tag,0,sizeof(tag));
	int cnt=0;
	tag[0]=tag[1]=1;
	for(int i = 2; i<N; i++){
		if(!tag[i])	
		prime[cnt++]=i;
		for(int j=0;j<cnt && prime[j]*i<N; j++){
			tag[i*prime[j]] = 1;//prime[j]是素数,它的倍数也是素数 
			if(i % prime[j]==0)
				break;//i是某个素数的倍数,直接跳出 
		}
	}
}
ll gcd(ll a,ll b)
{
	if(b!=0)return gcd(b,a%b);
	else return a;
}
ll f(ll x)
{
	int ans=0;
	while(x)
	{
		ans+=x%10;
		x/=10;
	}
	return ans;
}
int main()
{
	int n;
	cin>>n;
	ll x;
	//cout<<gcd(2,2);
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(gcd(f(x),x)!=1)cout<<x;
		else if(gcd(f(x+1),x+1)!=1)cout<<x+1;
		else if(gcd(f(x+2),x+2)!=1)cout<<x+2;
		else if(gcd(f(x+3),x+3)!=1)cout<<x+3;
		cout<<endl;
	}
	cout<<endl;
}
上一篇:CodeCraft-21 and Codeforces Round #711 (Div. 2)


下一篇:CodeCraft-20 (Div. 2) 总结