Codeforces Round #643 (Div. 2) A. Sequence with Digits 題解(打表)

題目鏈接

題目大意

給你a[1]和k,要你求a[k] a[n+1]=a[n]+minDigit(a[n])⋅maxDigit(a[n]).

題目思路

其實你會發現只要有0就會後面一直爲0,打表發現規律即可

代碼

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=3e5+5;
ll t,x,k;
int main(){
    scanf("%lld",&t);
    while(t--){
        scanf("%lld %lld",&x,&k);
        for(ll i=1;i<=k-1;i++){
            ll temp=x,mi=11,ma=-1;
            while(temp){
                mi=min(mi,temp%10);
                ma=max(ma,temp%10);
                temp=temp/10;
            }
            x=x+mi*ma;
            if(mi==0){
                break;
            }
        }
        printf("%lld\n",x);
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章