This article describes how to write a small program to solve an interesting abnormal Olympiad question:
Six people were born in April 11 and all of them belong to cows. The product of their years is 17597125. what is the sum of their years?
If you are an expert in mathematics and have come up with a mathematical solution. Please leave your method in the comment below.
If you are a programming expert and come up with a better algorithm than the following, please leave your method behind.
If you think about it, but still do not understand it. Let's look at the following program.
class Gusse { public static void main(String[] args){ int sut1=1,sut2=1,sut3=1,sut4=1,sut5=1,sut6=1; long mul=0,sum=0; for(sut1=1;sut1<=15;sut1++){ for(int n2=0;n2<=10;n2++){ sut2=sut1+n2*12; for(int n3=0;n3<=10;n3++){ sut3=sut1+n3*12; for(int n4=0;n4<=10;n4++){ sut4=sut1+n4*12; for(int n5=0;n5<=10;n5++){ sut5=sut1+n5*12; for(int n6=0;n6<=10;n6++){ sut6=sut1+n6*12; if((mul=sut1*sut2*sut3*sut4*sut5*sut6)==17597125){ System.out.println("sut1="+sut1); System.out.println("n2="+n2); System.out.println("n3="+n3); System.out.println("n4="+n4); System.out.println("n5="+n5); System.out.println("n6="+n6); System.out.println("sum="+(sum=sut1+sut2+sut3+sut4+sut5+sut6)); break; } } } } } } } } }
Copy the program intact to notepad, and run it in java to get the result.
The above is the detailed content of the code used to write a small program to solve an interesting abnormal Olympics question. For more information, see other related articles in the first PHP community!