필터 지우기
필터 지우기

How to find the 4th special number among pentagonal and triangular numbers

조회 수: 1 (최근 30일)
A pentagonal number is defined by p(n) = (3n^2 – n)/2, where n is an integer starting from 1. Therefore, the first 12 pentagonal numbers are 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, 176 and 210.
A triangular number is defined by t(n) = (n^2 + n)/2, where n is an integer starting from 1. Therefore, the first 12 triangular numbers are 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66 and 78.
From the above example, the number 1 is considered 'special' because it is both a pentagonal (p=1) and a triangular number (t=1). Determine the 4th 'special' number (i.e. where p=t) that exists assuming the number 1 to the be first 'special' number.

채택된 답변

Chunru
Chunru 2021년 4월 23일
편집: Chunru 2021년 4월 23일
n = 1:5000;
p = (3*n.^2 - n) / 2;
t = (n.^2 + n ) /2;
a = intersect(p, t);
disp(a)
The special number is 7906276

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by