Home php教程 php手册 把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11

把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11

Jun 06, 2016 pm 08:37 PM

把1316这个数表示成两个数的和,其中一个为13的倍数,另一个是11的倍数,求这两个数。

算法分析:

1316,显然1300是13的倍数,但16不是11的倍数,可以想到从1300上任意减去N个13的倍数其结果仍然是13的倍数,那么只要16加上这个减去的N个13的倍数其和是11的倍数,这两个数就解出来了,答案可能不只一个,但是我们只求一对解就可以了。

仔细观察不难发现:(16+13*3)+(1300-13*3)=1316,但是我们需要用代码实现:
代码如下:
$n=1316;
$i=0;//减去的第N个13,进行初始化为0
$y=16+13*$i;//1316分出来的16加上N个13,这里初始化为16
while($y%11!=0){//如果16加上N个13的和不能整除11
$i++;//再加一个13
$y=16+13*$i;
}

echo '$x='.($n-$y).'
';
echo '$y='.$y;
?>
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)