Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Chunru
Chunru am 23 Apr. 2021
Bearbeitet: Chunru am 23 Apr. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by