diff options
| author | Andrew Shitov <andy@shitov.ru> | 2020-12-04 09:17:37 +0100 |
|---|---|---|
| committer | Andrew Shitov <andy@shitov.ru> | 2020-12-04 09:17:37 +0100 |
| commit | fdd800775ca52e7600d78f38e5345a5197cc086c (patch) | |
| tree | 83e6da7d9535c716d29a57bab98f2a91cdcf4994 /challenge-089/ash/pascal | |
| parent | d19b0f983bbefca06f6139624711c079ac18eb6e (diff) | |
| download | perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.gz perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.tar.bz2 perlweeklychallenge-club-fdd800775ca52e7600d78f38e5345a5197cc086c.zip | |
Week 89 Issue 1
Diffstat (limited to 'challenge-089/ash/pascal')
| -rw-r--r-- | challenge-089/ash/pascal/ch-1.pas | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-089/ash/pascal/ch-1.pas b/challenge-089/ash/pascal/ch-1.pas new file mode 100644 index 0000000000..aeb64d4b38 --- /dev/null +++ b/challenge-089/ash/pascal/ch-1.pas @@ -0,0 +1,40 @@ +(* + To compile and run: + $ fpc ch-1.pas + $ ./ch-1 100 + 13015 +*) + +program Hello(input, output); + +uses sysutils; + +var + n, x, y, s: integer; + +function gcd(a, b: integer): integer; +var + t: integer; +begin + while b <> 0 do begin + t := b; + b := a mod b; + a := t; + end; + + gcd := a +end; + +begin + if paramCount() = 0 then + n := 3 + else + n := StrToInt(paramStr(1)); + + s := 0; + for x := 1 to n do + for y := x + 1 to n do + s += gcd(x, y); + + writeln(s); +end. |
