Menu
Coddy logo textTech

A problem

Coddyの「数学パズル」コースのレッスン 2/20。

10未満の自然数のうち、3または5の倍数であるものをすべて挙げると、3、5、6、9になります。

これらの倍数の合計23 (3 + 5 + 6 + 9 = 23)です。

100未満、1000未満の3または5の倍数の合計をそれぞれ求めてください...

challenge icon

チャレンジ

簡単

整数 N を入力として受け取り、N 未満の 3 または 5 の倍数の合計を返す関数 calc を作成してください。

例えば、N=10 の場合、3 + 5 + 6 + 9 = 23 となるため、関数は 23 を返します。

自分で試してみよう

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"

int main() {
    int n;
    if (scanf("%d", &n) != 1) n = 0;
    int r = calc(n);
    printf("%d\n", r);
    return 0;
}

数学パズルのすべてのレッスン

2Multiples of 3 or 5

A problemA solution with no loops

5Diophantine Equation

IntroductionA problem