Solution to a problem changing the number P2821 []

Foreword

This question really is a good question.

text

analysis

First of all, we think, a number of sub changing what conditions should be met.

There can not exceed the maximum quality factor 9 9 medium basis.

Then, find k k parent minimum number of changes to k k from 9 9 to 2 2 to break down k k , then save it, and finally the anti output.

why?

  1. in order to k k the minimum number of changes in the parent, our first 1 1 Ge as possible to ensure that the number of bits less.

  2. Under the premise of digits as little as possible, we want the number as small as possible,

#include <bits/stdc++.h>
using namespace std;
int x=9,a[1010],len,l=1;
vector<int>v;
int main(){
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar());
	for(;isdigit(ch);ch=getchar())a[++len]=ch-'0';//读入
	while(x>=2){
		int y=0;
		for(int i=1;i<=len;i++){
			y=y*10+a[i];
			y%=x;
		}
		if(y)x--;//如果不能整除
		else{
			v.push_back(x);//存入
			for(int i=1;i<=len;i++){
				y=y*10+a[i];
				a[i]=y/x;y%=x;//除
			}if(a[l]==0)l++;
		}
	}if(len!=l)puts("There is no such number!");
	else for(int i=v.size()-1;i>=0;i--)cout<<v[i];//反着输出
	return 0;
}

postscript

If you have questions, you can write it down in the comments section, so that a more complete solution of this problem.

Published 41 original articles · won praise 61 · views 642

Guess you like

Origin blog.csdn.net/qq_46230164/article/details/105313395