Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Syed Hafiz
Syed Hafiz le 23 Avr 2021
Modifié(e) : Chunru le 23 Avr 2021
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.

Réponse acceptée

Chunru
Chunru le 23 Avr 2021
Modifié(e) : Chunru le 23 Avr 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

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by