Codeforces Round #643 (Div. 2) A Sequence with Digits(分析,暴力)

这题刚开始被数据吓住了,想到只要出现0那就美滋滋,毕竟后面怎么加都是0,就不用看了。而0在1000次以内一定会出现,这个其实是有官方证明的,但是我更倾向于打表然后找找规律。

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll getAdd(ll x){
	ll m1=10,m2=0;
	while(x>0){
		ll y=x%10;
		x/=10;
		m1=min(m1,y);
		m2=max(m2,y);
	}
	return m1*m2;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ll x,k;
		cin>>x>>k;
		k--;
		while(k--){
			ll y=getAdd(x);
			if(y==0)break;
			x+=y;
		}
		cout<<x<<endl;
	}
} 
原创文章 38 获赞 7 访问量 1728

猜你喜欢

转载自blog.csdn.net/Alanrookie/article/details/106170632