Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Accepted Answer

Chunru
Chunru on 23 Apr 2021
Edited: Chunru on 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

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!