結果

問題 No.442 和と積
ユーザー AmaneAmane
提出日時 2020-07-17 00:49:57
言語 Swift
(5.10.0)
結果
WA  
実行時間 -
コード長 839 bytes
コンパイル時間 11,519 ms
コンパイル使用メモリ 173,780 KB
実行使用メモリ 13,428 KB
最終ジャッジ日時 2023-08-20 16:14:07
合計ジャッジ時間 9,623 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.swift:23:9: warning: variable 'gcdNum' was never mutated; consider changing to 'let' constant
    var gcdNum = gcd(num1, num2)
    ~~~ ^
    let

ソースコード

diff #

import Foundation
//最大公約数を求める関数
func gcd(_ num1: Int, _ num2: Int) -> Int {
   let r = num1 % num2
   if r != 0 {
       return gcd(num2, r)
   } else {
       return num2
   }
}
//3つ以上の数の最大公約数を求める
func gcdArr(_ numArr: [Int]) -> Int {
    var ans: Int = numArr[0]
    for i in numArr {
        ans = gcd(ans, i)
    }
    return ans
}

//最小公倍数を求める関数
func lcm(_ num1: Int, _ num2: Int) -> Int {
    
    var gcdNum = gcd(num1, num2)
    return num1*num2/gcdNum
}

//3つ以上の最大公約数を求める
func lcmArr(_ numArr: [Int]) -> Int {
    var ans: Int = 1
    for i in numArr {
        ans = lcm(ans, i)
    }
    return ans
}


let ri = Int(readLine()!)!
let ra = readLine()!.split(separator: " ").map({Int($0)!})

print(gcd(ra[0]+ra[1],ra[0]*ra[1]))
0