Menu
Coddy logo textTech

A problem

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

三角数、五角数、六角数(Project Euler, Problem #45)

三角数、五角数、および六角数は、以下の式によって生成されます:

三角数  T(n)=n(n+1)/2   1, 3, 6, 10, 15, ...

五角数  P(n)=n(3n−1)/2   1, 5, 12, 22, 35, ...

六角数  H(n)=n(2n−1)   1, 6, 15, 28, 45, ...

T(1)=P(1)=H(1)=1 であり、T(285) = P(165) = H(143) = 40755 であることが確認できます。

五角数かつ六角数でもある、次の三角数を求めてください。

challenge icon

チャレンジ

難しい

問題を解決し、その問題の最初の3つの解のベクトルを返す関数 calc を作成してください。これは [1, 40755, ...] を意味します。

自分で試してみよう

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

int main() {
    int rs = 0;
    int* r = calc(&rs);
    for (int i = 0; i < rs; i++) {
        if (i > 0) printf(" ");
        printf("%d", r[i]);
    }
    printf("\n");
    return 0;
}

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

5Diophantine Equation

IntroductionA problem