1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

合成数列の和Advent Calendar 2018

Day 24

合成数列の和(advent calendar2018,Nim)

Last updated at Posted at 2018-12-24

今見ましたら、advent calendar 2018の合成数列の和、12/24が埋まっていませんでした。
また、Nimがないなあと思っていましたので、参加します。
イテレータに挑戦しようかと思いましたが、求められているのは合計だけですので、
普通にプロシージャで書きます。
初心者の素朴なコードですので説明はいらないでしょう。

import os
import strutils
import math

proc sync(x:int): bool =
  result = false
  for i in 2..x.float.sqrt.int :
    if x mod i == 0:
      result=true

proc sumsync(b: int): int =
  var res=4
  var cou=1
  var sum=0
  while cou <= b:
    if sync(res):
      sum=sum+res
      inc(cou)
    inc(res)
  return sum

#echo sumsync(100)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?