題目:2520是最小的能夠被1到10整除的數(shù)。最小的能夠被1到20整除的正數(shù)是多少啥辨?
Java:
int haha = 20;
int count = 0; //被整除的個數(shù)
int multiple = haha;
while (true){
for (int j = 1;j<=haha;j++){
if(multiple%j==0)
count++;
else{
count = 0;
break;
}
}
if(count==haha){
break;
}
multiple += haha;
}
Log.e("multiple===",multiple+"");
python3:
haha = 20
count = 0
multiple = haha
while True:
for j in range(1,haha+1):
if multiple % j == 0:
count += 1
else:
count = 0
break
if count==haha:
break
multiple += haha
print("multiple=這算法實在太慢啦==", multiple)
圖片來自優(yōu)美圖
誰若游戲人生涡匀,他就一事無成;誰不能主宰自己溉知,便永遠是一個奴隸陨瘩。
——歌德