生成元(JAVA语言)

package 第三章;


import java.util.Scanner;


public class 生成元 {


public static void main(String[] args) {
// TODO Auto-generated method stub
final int max=100005;
int a[]=new int[max];
for(int i=1;i<max;i++) {
int x=i,y=i;
while(x>0) {
y+=x%10;
x/=10;
}

if(y<max&&(a[y]>i||a[y]==0)) {
a[y]=i;
}
}
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
System.out.println(a[n]);
}


}

猜你喜欢

转载自blog.csdn.net/liuyaoyun/article/details/79342223