Icosikaipentagon-Zahl
Bei einer gegebenen Zahl N besteht die Aufgabe darin, die N -te Icosikaipentagon-Zahl zu finden .
Eine Icosikaipentagon-Zahl ist eine Klasse von Figurenzahlen. Es hat ein 25-seitiges Polygon namens Icosikaipentagon. Die N-te Icosikaipentagon-Zahl zählt die 25 Punkte und alle anderen Punkte umgeben sich mit einer gemeinsamen gemeinsamen Ecke und bilden ein Muster. Die ersten paar Icosikaipentagonol-Zahlen sind 1, 25, 72, 142 …
Beispiele:
Eingabe: N = 2
Ausgabe: 25
Erklärung:
Die zweite Icosikaipentagonol-Zahl ist 25.Eingabe: N = 3
Ausgabe: 72
Ansatz: Die N-te Ikosikaipentagon-Zahl ergibt sich aus der Formel:
- N-ter Term des S-seitigen Polygons =
- Daher ist der N-te Term des 25-seitigen Polygons gegeben durch:
Unten ist die Implementierung des obigen Ansatzes:
C++
// C++ program to find the N-th // Icosikaipentagon Number #include <bits/stdc++.h> using namespace std; // Function to find the N-th // icosikaipentagon Number int icosikaipentagonNum(int N) { return (23 * N * N - 21 * N) / 2; } // Driver code int main() { int n = 3; cout << "3rd icosikaipentagon Number is " << icosikaipentagonNum(n); return 0; }
Java
// Java program to find N-th // icosikaipentagon number class GFG{ // Function to find the nth // icosikaipentagon number static int icosikaipentagonNum(int N) { return (23 * N * N - 21 * N) / 2; } // Driver code public static void main(String[] args) { int n = 3; System.out.print("3rd icosikaipentagon Number is " + icosikaipentagonNum(n)); } } // This code is contributed by shubham
Python3
# Python3 program to find the N-th # icosikaipentagon number # Function to find the N-th # icosikaipentagon number def icosikaipentagonNum(N): return (23 * N * N - 21 * N) // 2 # Driver code n = 3 print("3rd icosikaipentagon Number is ", icosikaipentagonNum(n)) # This code is contributed by yatinagg
C#
// C# program for the above approach using System; class GFG{ // Finding the nth chiliagon number static int Icosikaipentagon(int n) { return (23 * n * n - 21 * n) / 2; } // Driver code public static void Main() { int n = 3; Console.Write("3rd Icosikaipentagon Number is = " + Icosikaipentagon(n)); } } // This code is contributed by shivanisinghss2110
Javascript
<script> // Javascript program to find the N-th // Icosikaipentagon Number // Function to find the N-th // icosikaipentagon Number function icosikaipentagonNum(N) { return parseInt((23 * N * N - 21 * N) / 2); } // Driver code let n = 3; document.write("3rd icosikaipentagon Number is " + icosikaipentagonNum(n)); // This code is contributed by rishavmahato348. </script>
Die 3. Ikosikai-Pentagon-Zahl ist 72
Zeitkomplexität: O(1)
Hilfsraum: O(1)
Referenz: http://www.2dcurves.com/line/linep.html
Falls Sie an Live-Kursen mit Experten teilnehmen möchten , beziehen Sie sich bitte auf DSA Live-Kurse für Berufstätige und Competitive Programming Live for Students .