A. Sequence with Digits(思维)

A. Sequence with Digits

公式: a n + 1 = a n + m i n D i g i t ( a n ) ⋅ m a x D i g i t ( a n ) a_{n+1}=a_n+minDigit(a_n)⋅maxDigit(a_n) an+1=an+m i n D i g i t ( an)maxDigit(an)
含义: m i n D i g i t ( a n ) , a n minDigit(a_n),a_n m i n D i g i t ( an)anThe minimum value in each decimal position of. max D igit (an), an maxDigit(a_n), a_nmaxDigit(an)anThe maximum value in each decimal position of.
For example: min Digit (an) = 0 for the number 83901 , max Digit (an) = 9 minDigit(a_n) = 0, maxDigit(a_n) = 9m i n D i g i t ( an)=0maxDigit(an)=9

Meaning of the title: give a 1, k a_1, ka1, K is calculated according to the formulaak a_kak

Idea: When min Digit (an) = = 0 minDigit(a_n) = =0m i n D i g i t ( an)==At 0 , the entire number will no longer change. You can directly output the answer.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Max(ll x) {
    
    
	ll mx = x%10;
	x /= 10;
	while(x) mx = max(x%10, mx), x /= 10;
	return mx;
}
ll Min(ll x) {
    
    
	ll mi = x%10;
	x /= 10;
	while(x) mi = min(x%10, mi), x /= 10;
	return mi;
}

int main() {
    
    
	int t;
	scanf("%d", &t);
	while(t--) {
    
    
		ll n, m, x, y;
		scanf("%lld%lld", &n, &m);
		for(int i=1; i<m; i++) {
    
    
			x = Max(n), y = Min(n);
			if(y == 0) break;
			n = n + x*y;
		}
		printf("%lld\n", n);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45363113/article/details/106877877