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