其他分享
首页 > 其他分享> > CodeCraft-21 and Codeforces Round #711 (Div. 2)

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

作者:互联网

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

题号题目考点
AGCD Sum签到,模拟
BBox Fitting贪心
CPlanar Reflections规律+暴力(直接乱搞就对了)
DBananas in a Microwave思维题,贪心
ETwo Houses
Fhttps://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;
}

标签:prime,CodeCraft,ch,21,int,ll,Codeforces,while,tag
来源: https://blog.csdn.net/qq_35975367/article/details/115670212