Pairing of integer multiples


Submit solution

Points: 20
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

題目說明

<1123檢定考題>
程式輸入一連串數字,第1個輸入值是n表示陣列長度,第2到n+1個輸入值是陣列內容,輸入值都是大於0且小於1000的整數。n大於等於2。
程式計算陣列中總共有幾組「倍數配對」並輸出該數量。對於陣列nums,對於任意兩個索引 i 和 j,
若 nums[i] 是 nums[j] 的整數倍或 nums[j] 是 nums[i] 的整數倍,則 nums[i] 和 nums[j] 為一個「倍數配對」。

輸入

輸入一連串數字,第1個輸入值是n表示陣列長度,第2到n+1個輸入值是陣列內容,輸入值都是大於0且小於1000的整數。n大於等於2。

輸出

計算陣列中總共有幾組「倍數配對」並輸出該數量。

sample input0

4 3 6 12 7

sample output0

3

說明:6和12都是3的整數倍,12是6的整數倍。

sample input1

4 3 3 3 7

sample output1

3

說明:3是3的整數倍

sample input2

2 3 4

sample output2

0

Comments

There are no comments at the moment.