例:求10-50之间的是7的倍数的值的和.有特殊奖励
经常在学php的时候总会遇到一些题.什么水仙花啊,什么素数的和之类的.今天我看到某个网站上的这道题,对于这道题的答案,基本都是以下这个函数.
function newSumMultiple($min,$max,$multiple){
$sum = 0;
for(;$min
<p>今天我突发奇想,一直都是这样子,老师教的时候都是照本宣科,真的是无语.于是我就想了以下这种思路.</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20e352aa140.jpg" alt="Build MCP servers and clients for PHP applications with the official PHP SDK" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="overflowclass">Build MCP servers and clients for PHP applications with the official PHP SDK</a>
<p class="overflowclass">使用官方Model Context Protocol PHP SDK将PHP应用程序功能暴露为MCP工具、资源和提示,用于代理工作流。</p>
</div>
<a rel="nofollow" href="/xiazai/skill13222" title="Build MCP servers and clients for PHP applications with the official PHP SDK" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<pre class="brush:php;toolbar:false;">function sumMultiple($min,$max,$multiple){
$remainder=$min % $multiple;
if($remainder){
$remainder = $min + $remainder + 1;
$min = $remainder;
}else{
$remainder = $min;
}
$sum = 0;
while(true){
$sum += $remainder;
$min += $multiple;
if($min >= $max){
break;
}
$remainder = $remainder + $multiple;
}
return $sum;
}
求一个新的算法,最好附上代码.
回复内容:
例:求10-50之间的是7的倍数的值的和.有特殊奖励
经常在学php的时候总会遇到一些题.什么水仙花啊,什么素数的和之类的.今天我看到某个网站上的这道题,对于这道题的答案,基本都是以下这个函数.
function newSumMultiple($min,$max,$multiple){
$sum = 0;
for(;$min
<p>今天我突发奇想,一直都是这样子,老师教的时候都是照本宣科,真的是无语.于是我就想了以下这种思路.</p>
<pre class="brush:php;toolbar:false;">function sumMultiple($min,$max,$multiple){
$remainder=$min % $multiple;
if($remainder){
$remainder = $min + $remainder + 1;
$min = $remainder;
}else{
$remainder = $min;
}
$sum = 0;
while(true){
$sum += $remainder;
$min += $multiple;
if($min >= $max){
break;
}
$remainder = $remainder + $multiple;
}
return $sum;
}
求一个新的算法,最好附上代码.
用 min, max 分别整除 multiple 得到上下界然后用等差数列求和公式










