艾尼斯化妆学校:两个自然数的和是1999,这两个数的积的首、末位数字之和的最大值是多少?

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 19:17:13

最大值17:
991×1008
9+8=17

首位数字最大是9可确定
两个数的末位数字加起来是9,可能是09,18,27等等,其中乘积末位数最大的是8所以首位和末位数字之和最大值为17

用下面的程序计算可得到答案
public class cacl{
public static void main(String[] args){
int x = 1;
int sum = 0;
for (int i = 1; i<1999; i++){
int temp = x*(1999-x);
String s = Integer.toString(temp);
int first = Integer.parseInt(s.substring(0,1));
int last = Integer.parseInt(s.substring(s.length()-1,s.length()));
if(sum<=(last+first)){
System.out.println("***************");
System.out.println("x is: "+x+" and y is: "+(1999-x));
System.out.println("x*y is: "+temp);
sum = last + first;
System.out.println("the sum is: "+sum);
System.out.println("");
}
x++;
}
}
}
运行结果是:
***************
x is: 1 and y is: 1998
x*y is: 1998
the sum is: 9

***************
x is: 3 and y is: 1996
x*y is: 5988
the sum is: 13

***************
x is: 26 and y is: 1973
x*y is: 51298
the sum is: 13

***************
x is: 28 and y is: 1971
x*y is: 55188
the sum is: 13

***************
x is: 31 and y is: 1968
x*y is: 61008
the sum is: 14

***************
x is: 33 and y is: 1966
x*y is: 64878
the sum is: 14

***************
x is: 36 and y is: 1963
x*y is: 70668
the sum is: 15

***************
x is: 38 and y is: 1961
x*y is: 74518
the sum is: 15

***************
x is: 41 and y is: 1958
x*y is: 80278
the sum is: 16

***************
x is: 43 and y is: 1956
x*y is: 84108
the sum is: 16

***************
x is: 46 and y is: 1953
x*y is: 89838
the sum is: 16

***************
x is: 48 and y is: 1951
x*y is: 93648
the sum is: 17

中间省略若干结果。。。

***************
x is: 1273 and y is: 726
x*y is: 924198
the sum is: 17

***************
x is: 1276 and y is: 723
x*y is: 922548
the sum is: 17

***************
x is: 1278 and y is: 721
x*y is: 921438
the sum is 17