Algorithm analysis:
1316, obviously 1300 is a multiple of 13, but 16 is not a multiple of 11. You can think of subtracting N multiples of 13 from 1300 and the result is still a multiple of 13, then as long as 16 is added The sum of the N multiples of 13 subtracted above is a multiple of 11. These two numbers can be solved. There may be more than one answer, but we only need one pair of solutions.
It is not difficult to find if you look closely: (16+13*3) + (1300-13*3) = 1316, but we need to use code to implement it:
Copy Code The code is as follows:
$n=1316;
$i=0;//Subtract the Nth 13, proceed Initialized to 0
$y=16+13*$i;//16 divided from 1316 plus N 13s, here initialized to 16
while($y%11!=0){//If The sum of 16 plus N 13 cannot be divisible by 11
$i++;//Add another 13
$y=16+13*$i;
}
echo '$x ='.($n-$y).'
';
echo '$y='.$y;
?>
http://www.bkjia.com/PHPjc/323644.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323644.htmlTechArticleAlgorithm analysis: 1316, obviously 1300 is a multiple of 13, but 16 is not a multiple of 11, you can think of starting from 1300 Arbitrarily subtracting N multiples of 13, the result is still a multiple of 13, then as long as 16 is added to this subtraction...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn