Closed. This question needs details or clarity. It is not currently accepting answers. Learn more。
想改进这个问题吗?添加细节并通过editing this post澄清问题。
假设我有以下系列:
(x+1) mod 10 =0, (x+2) mod 10 = 0, (x+3) mod 10 = 0, .........,(x+11) mod 10 =0, (x+12) mod 10 = 0,........
我需要找到x的方法。x+任何数字都应该是10,20,30,40,50….
谢谢你的帮助。
最佳答案
X的最小可能值
a)X必须大于0:
$x = 10 - ( $y % 10 )
示例:
$y = 0 > $x = 10 (tot = 10)
$y = 1 > $x = 9 (tot = 10)
$y = 2 > $x = 8 (tot = 10)
$y = 10 > $x = 10 (tot = 20)
b)x可以是0:
$x = 10 * ( ($y % 10)>0 ) - ( $y % 10 )
示例:
$y = 0 > $x = 0 (tot = 0)
$y = 1 > $x = 9 (tot = 10)
$y = 2 > $x = 8 (tot = 10)
$y = 10 > $x = 0 (tot = 10)
PhpFiddle demo
X的“Y乘法”值
$x = ( $y * 10 ) - $y
(不需要括号)
示例:
$y = 1 > $x = 9 (tot = 10)
$y = 2 > $x = 18 (tot = 20)
$y = 8 > $x = 72 (tot = 80)
PhpFiddle demo
我认为代码是不言而喻的。。。
关于php - 在(x + 1)mod 10 = 0中查找x的PHP算法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35522682/
10-12 07:18