Dato un array arr[] di dimensione N e un numero intero X . Scopri se c'è una tripletta nell'array che somma il numero intero indicato X .
Esempi:
Pratica consigliata Somma di triplette nell'array Provalo!Ingresso: matrice = {12, 3, 4, 1, 6, 9}, somma = 24;
Produzione: 12, 3, 9
Spiegazione: È presente una terzina (12, 3 e 9).
nell'array la cui somma è 24.Ingresso: matrice = {1, 2, 3, 4, 5}, somma = 9
Produzione: 5, 3, 1
Spiegazione: È presente una terzina (5, 3 e 1).
nell'array la cui somma è 9.
Somma tripletta nell'array (somma 3) generando tutte le triplette:
Un metodo semplice è generare tutte le triplette possibili e confrontare la somma di ciascuna tripletta con il valore dato. Il codice seguente implementa questo semplice metodo utilizzando tre cicli nidificati.
Approccio passo dopo passo:
- Dato un array di lunghezza N e una somma S
- Crea tre cicli nidificati: il primo ciclo viene eseguito dall'inizio alla fine (contatore del ciclo i), il secondo ciclo viene eseguito da io+1 alla fine (contatore del ciclo j) e il terzo ciclo parte da j+1 per terminare (contatore del ciclo k)
- Il contatore di questi cicli rappresenta l'indice di 3 elementi delle terzine.
- Trova la somma di iesimo, jesimo e kesimo elemento. Se la somma è uguale alla somma data. Stampa la terzina e spezzala.
- Se non c'è una terzina, stampa che non esiste una terzina.
Di seguito è riportata l’implementazione dell’approccio di cui sopra:
C++
#include> using> namespace> std;> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> bool> find3Numbers(>int> A[],>int> arr_size,>int> sum)> {> >// Fix the first element as A[i]> >for> (>int> i = 0; i { // Fix the second element as A[j] for (int j = i + 1; j { // Now look for the third number for (int k = j + 1; k { if (A[i] + A[j] + A[k] == sum) { cout << 'Triplet is ' << A[i] << ', ' << A[j] << ', ' << A[k]; return true; } } } } // If we reach here, then no triplet was found return false; } /* Driver code */ int main() { int A[] = { 1, 4, 45, 6, 10, 8 }; int sum = 22; int arr_size = sizeof(A) / sizeof(A[0]); find3Numbers(A, arr_size, sum); return 0; } // This is code is contributed by rathbhupendra> |
>
>
C
#include> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> bool> find3Numbers(>int> A[],>int> arr_size,>int> sum)> {> >int> l, r;> >// Fix the first element as A[i]> >for> (>int> i = 0; i // Fix the second element as A[j] for (int j = i + 1; j // Now look for the third number for (int k = j + 1; k if (A[i] + A[j] + A[k] == sum) { printf('Triplet is %d, %d, %d', A[i], A[j], A[k]); return true; } } } } // If we reach here, then no triplet was found return false; } /* Driver program to test above function */ int main() { int A[] = { 1, 4, 45, 6, 10, 8 }; int sum = 22; int arr_size = sizeof(A) / sizeof(A[0]); find3Numbers(A, arr_size, sum); return 0; }> |
>
>
Giava
// Java program to find a triplet> class> FindTriplet {> >// returns true if there is triplet with sum equal> >// to 'sum' present in A[]. Also, prints the triplet> >boolean> find3Numbers(>int> A[],>int> arr_size,>int> sum)> >{> >int> l, r;> >// Fix the first element as A[i]> >for> (>int> i =>0>; i 2; i++) { // Fix the second element as A[j] for (int j = i + 1; j 1; j++) { // Now look for the third number for (int k = j + 1; k if (A[i] + A[j] + A[k] == sum) { System.out.print('Triplet is ' + A[i] + ', ' + A[j] + ', ' + A[k]); return true; } } } } // If we reach here, then no triplet was found return false; } // Driver program to test above functions public static void main(String[] args) { FindTriplet triplet = new FindTriplet(); int A[] = { 1, 4, 45, 6, 10, 8 }; int sum = 22; int arr_size = A.length; triplet.find3Numbers(A, arr_size, sum); } }> |
>
>
Python3
# Python3 program to find a triplet> # that sum to a given value> # returns true if there is triplet with> # sum equal to 'sum' present in A[].> # Also, prints the triplet> def> find3Numbers(A, arr_size,>sum>):> ># Fix the first element as A[i]> >for> i>in> range>(>0>, arr_size>->2>):> ># Fix the second element as A[j]> >for> j>in> range>(i>+> 1>, arr_size>->1>):> > ># Now look for the third number> >for> k>in> range>(j>+> 1>, arr_size):> >if> A[i]>+> A[j]>+> A[k]>=>=> sum>:> >print>(>'Triplet is'>, A[i],> >', '>, A[j],>', '>, A[k])> >return> True> > ># If we reach here, then no> ># triplet was found> >return> False> # Driver program to test above function> A>=> [>1>,>4>,>45>,>6>,>10>,>8>]> sum> => 22> arr_size>=> len>(A)> find3Numbers(A, arr_size,>sum>)> # This code is contributed by Smitha Dinesh Semwal> |
>
>
C#
// C# program to find a triplet> // that sum to a given value> using> System;> class> GFG {> >// returns true if there is> >// triplet with sum equal> >// to 'sum' present in A[].> >// Also, prints the triplet> >static> bool> find3Numbers(>int>[] A,> >int> arr_size,> >int> sum)> >{> >// Fix the first> >// element as A[i]> >for> (>int> i = 0;> >i // Fix the second // element as A[j] for (int j = i + 1; j // Now look for // the third number for (int k = j + 1; k if (A[i] + A[j] + A[k] == sum) { Console.WriteLine('Triplet is ' + A[i] + ', ' + A[j] + ', ' + A[k]); return true; } } } } // If we reach here, // then no triplet was found return false; } // Driver Code static public void Main() { int[] A = { 1, 4, 45, 6, 10, 8 }; int sum = 22; int arr_size = A.Length; find3Numbers(A, arr_size, sum); } } // This code is contributed by m_kit> |
>
>
Javascript
> // Javascript program to find a triplet> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> function> find3Numbers(A, arr_size, sum)> {> >let l, r;> >// Fix the first element as A[i]> >for> (let i = 0; i { // Fix the second element as A[j] for (let j = i + 1; j { // Now look for the third number for (let k = j + 1; k { if (A[i] + A[j] + A[k] == sum) { document.write('Triplet is ' + A[i] + ', ' + A[j] + ', ' + A[k]); return true; } } } } // If we reach here, then no triplet was found return false; } /* Driver code */ let A = [ 1, 4, 45, 6, 10, 8 ]; let sum = 22; let arr_size = A.length; find3Numbers(A, arr_size, sum); // This code is contributed by Mayank Tyagi> |
>
>
PHP
// PHP program to find a triplet // that sum to a given value // returns true if there is // triplet with sum equal to // 'sum' present in A[]. // Also, prints the triplet function find3Numbers($A, $arr_size, $sum) { $l; $r; // Fix the first // element as A[i] for ($i = 0; $i <$arr_size - 2; $i++) { // Fix the second // element as A[j] for ($j = $i + 1; $j <$arr_size - 1; $j++) { // Now look for the // third number for ($k = $j + 1; $k <$arr_size; $k++) { if ($A[$i] + $A[$j] + $A[$k] == $sum) { echo 'Triplet is', ' ', $A[$i], ', ', $A[$j], ', ', $A[$k]; return true; } } } } // If we reach here, then // no triplet was found return false; } // Driver Code $A = array(1, 4, 45, 6, 10, 8); $sum = 22; $arr_size = sizeof($A); find3Numbers($A, $arr_size, $sum); // This code is contributed by ajit ?>> |
>
>Produzione
Triplet is 4, 10, 8>
Analisi della complessità:
- Complessità temporale: SU3), Ci sono tre cicli nidificati che attraversano l'array, quindi la complessità temporale è O(n^3)
- Spazio ausiliario: O(1), poiché non è richiesto spazio aggiuntivo.
Somma tripletta nell'array (somma 3) utilizzando Tecnica dei due puntatori :
Ordinando l'array è possibile migliorare l'efficienza dell'algoritmo. Questo approccio efficiente utilizza il file tecnica dei due puntatori . Attraversa l'array e fissa il primo elemento della tripletta. Ora usa l'algoritmo Two Pointers per scoprire se esiste una coppia la cui somma è uguale a x – matrice[i] . L'algoritmo a due puntatori richiede tempo lineare, quindi è migliore di un ciclo annidato.
Approccio passo dopo passo:
- Ordina l'array indicato.
- Passa sull'array e fissa il primo elemento della possibile tripletta, arr[i] .
- Quindi fissa due puntatori, uno a io + 1 e l'altro a n-1 . E guarda la somma,
- Se la somma è inferiore alla somma richiesta, incrementare il primo puntatore.
- Altrimenti, se la somma è maggiore, diminuire il puntatore finale per ridurre la somma.
- Altrimenti, se la somma degli elementi su due puntatori è uguale alla somma data, stampa la terzina e spezza.
Di seguito è riportata l’implementazione dell’approccio di cui sopra:
C++
sciacallo contro lupo
// C++ program to find a triplet> #include> using> namespace> std;> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> bool> find3Numbers(>int> A[],>int> arr_size,>int> sum)> {> >int> l, r;> >/* Sort the elements */> >sort(A, A + arr_size);> >/* Now fix the first element one by one and find the> >other two elements */> >for> (>int> i = 0; i // To find the other two elements, start two index // variables from two corners of the array and move // them toward each other l = i + 1; // index of the first element in the // remaining elements r = arr_size - 1; // index of the last element while (l if (A[i] + A[l] + A[r] == sum) { printf('Triplet is %d, %d, %d', A[i], A[l],A[r]); return true; } else if (A[i] + A[l] + A[r] l++; else // A[i] + A[l] + A[r]>somma r--; } } // Se raggiungiamo qui, non è stata trovata alcuna tripletta return false; } /* Programma driver per testare la funzione sopra */ int main() { int A[] = { 1, 4, 45, 6, 10, 8 }; somma intera = 22; int arr_size = sizeof(A) / sizeof(A[0]); trova3Numeri(A, dimensione_arr, somma); restituire 0; } // Questo codice è un contributo di Aditya Kumar (adityakumar129)> |
>
>
C
// C program to find a triplet> #include> #include> #include> int> cmpfunc(>const> void>* a,>const> void>* b)> {> >return> (*(>int>*)a - *(>int>*)b);> }> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> bool> find3Numbers(>int> A[],>int> arr_size,>int> sum)> {> >int> l, r;> > >/* Sort the elements */> >qsort>(A, arr_size,>sizeof>(>int>), cmpfunc);> > >/* Now fix the first element one by one and find the> >other two elements */> >for> (>int> i = 0; i { // To find the other two elements, start two index // variables from two corners of the array and move // them toward each other l = i + 1; // index of the first element in the // remaining elements r = arr_size - 1; // index of the last element while (l if (A[i] + A[l] + A[r] == sum) { printf('Triplet is %d, %d, %d', A[i], A[l], A[r]); return true; } else if (A[i] + A[l] + A[r] l++; else // A[i] + A[l] + A[r]>somma r--; } } // Se raggiungiamo qui, non è stata trovata alcuna tripletta return false; } /* Programma driver per testare la funzione sopra */ int main() { int A[] = { 1, 4, 45, 6, 10, 8 }; somma intera = 22; int arr_size = sizeof(A) / sizeof(A[0]); trova3Numeri(A, dimensione_arr, somma); restituire 0; } // Questo codice è un contributo di Aditya Kumar (adityakumar129)> |
>
>
Giava
// Java program to find a triplet> class> FindTriplet {> >// returns true if there is triplet with sum equal> >// to 'sum' present in A[]. Also, prints the triplet> >boolean> find3Numbers(>int> A[],>int> arr_size,>int> sum)> >{> >int> l, r;> >/* Sort the elements */> >quickSort(A,>0>, arr_size ->1>);> >/* Now fix the first element one by one and find the> >other two elements */> >for> (>int> i =>0>; i 2; i++) { // To find the other two elements, start two // index variables from two corners of the array // and move them toward each other l = i + 1; // index of the first element in the // remaining elements r = arr_size - 1; // index of the last element while (l if (A[i] + A[l] + A[r] == sum) { System.out.print('Triplet is ' + A[i] + ', ' + A[l] + ', ' + A[r]); return true; } else if (A[i] + A[l] + A[r] l++; else // A[i] + A[l] + A[r]>somma r--; } } // Se raggiungiamo qui, non è stata trovata alcuna tripletta return false; } int partizione(int A[], int si, int ei) { int x = A[ei]; int i = (si - 1); intero j; per (j = si; j<= ei - 1; j++) { if (A[j] <= x) { i++; int temp = A[i]; A[i] = A[j]; A[j] = temp; } } int temp = A[i + 1]; A[i + 1] = A[ei]; A[ei] = temp; return (i + 1); } /* Implementation of Quick Sort A[] -->Array da ordinare si --> Indice iniziale ei --> Indice finale */ void quickSort(int A[], int si, int ei) { int pi; /* Indice di partizionamento */ if (si pi = partizione(A, si, ei); quickSort(A, si, pi - 1); quickSort(A, pi + 1, ei); } } // Programma driver da testare funzioni sopra public static void main(String[] args) { FindTriplet triplet = new int A[] = { 1, 4, 45, 6, 10, 8 } int sum = 22; lunghezza; triplet.find3Numbers(A, arr_size, sum); } }> |
>
>
Python3
# Python3 program to find a triplet> # returns true if there is triplet> # with sum equal to 'sum' present> # in A[]. Also, prints the triplet> def> find3Numbers(A, arr_size,>sum>):> ># Sort the elements> >A.sort()> ># Now fix the first element> ># one by one and find the> ># other two elements> >for> i>in> range>(>0>, arr_size>->2>):> > ># To find the other two elements,> ># start two index variables from> ># two corners of the array and> ># move them toward each other> > ># index of the first element> ># in the remaining elements> >l>=> i>+> 1> > ># index of the last element> >r>=> arr_size>->1> >while> (l if( A[i] + A[l] + A[r] == sum): print('Triplet is', A[i], ', ', A[l], ', ', A[r]); return True elif (A[i] + A[l] + A[r] |
>
>
C#
// C# program to find a triplet> using> System;> class> GFG {> >// returns true if there is triplet> >// with sum equal to 'sum' present> >// in A[]. Also, prints the triplet> >bool> find3Numbers(>int>[] A,>int> arr_size,> >int> sum)> >{> >int> l, r;> >/* Sort the elements */> >quickSort(A, 0, arr_size - 1);> >/* Now fix the first element> >one by one and find the> >other two elements */> >for> (>int> i = 0; i // To find the other two elements, // start two index variables from // two corners of the array and // move them toward each other l = i + 1; // index of the first element // in the remaining elements r = arr_size - 1; // index of the last element while (l if (A[i] + A[l] + A[r] == sum) { Console.Write('Triplet is ' + A[i] + ', ' + A[l] + ', ' + A[r]); return true; } else if (A[i] + A[l] + A[r] l++; else // A[i] + A[l] + A[r]>somma r--; } } // Se arriviamo qui, // non è stata trovata alcuna tripletta return false; } int partizione(int[] A, int si, int ei) { int x = A[ei]; int i = (si - 1); intero j; per (j = si; j<= ei - 1; j++) { if (A[j] <= x) { i++; int temp = A[i]; A[i] = A[j]; A[j] = temp; } } int temp1 = A[i + 1]; A[i + 1] = A[ei]; A[ei] = temp1; return (i + 1); } /* Implementation of Quick Sort A[] -->Array da ordinare si --> Indice iniziale ei --> Indice finale */ void quickSort(int[] A, int si, int ei) { int pi; /* Indice di partizionamento */ if (si pi = partizione(A, si, ei); quickSort(A, si, pi - 1); quickSort(A, pi + 1, ei); } } // Codice driver static void Main() { tripletta GFG = new GFG(); int[] A = new int[] { 1, 4, 45, 6, 10, 8 }; int somma = 22; (A, arr_size, sum); } } // Questo codice è fornito da mits> |
>
>
Javascript
> // Javascript program to find a triplet> // returns true if there is triplet with sum equal> // to 'sum' present in A[]. Also, prints the triplet> function> find3Numbers(A, arr_size, sum)> {> >let l, r;> >/* Sort the elements */> >A.sort((a,b) =>a-b);> >/* Now fix the first element one> >by one and find the> >other two elements */> >for> (let i = 0; i // To find the other two // elements, start two index // variables from two corners of // the array and move // them toward each other // index of the first element in the l = i + 1; // remaining elements // index of the last element r = arr_size - 1; while (l if (A[i] + A[l] + A[r] == sum) { document.write('Triplet is ' + A[i] + ', ' + A[l] + ', ' + A[r]); return true; } else if (A[i] + A[l] + A[r] l++; else // A[i] + A[l] + A[r]>somma r--; } } // Se raggiungiamo qui, non è stata trovata alcuna tripletta return false; } /* Programma driver per testare la funzione sopra */ let A = [ 1, 4, 45, 6, 10, 8 ]; poniamo la somma = 22; let arr_size = A.length; trova3Numeri(A, dimensione_arr, somma); // Questo codice è un contributo di Mayank Tyagi> |
>
>
PHP
// PHP program to find a triplet // returns true if there is // triplet with sum equal to // 'sum' present in A[]. Also, // prints the triplet function find3Numbers($A, $arr_size, $sum) { $l; $r; /* Sort the elements */ sort($A); /* Now fix the first element one by one and find the other two elements */ for ($i = 0; $i <$arr_size - 2; $i++) { // To find the other two elements, // start two index variables from // two corners of the array and // move them toward each other $l = $i + 1; // index of the first element // in the remaining elements // index of the last element $r = $arr_size - 1; while ($l <$r) { if ($A[$i] + $A[$l] + $A[$r] == $sum) { echo 'Triplet is ', $A[$i], ' ', $A[$l], ' ', $A[$r], '
'; return true; } else if ($A[$i] + $A[$l] + $A[$r] <$sum) $l++; else // A[i] + A[l] + A[r]>somma $r--; } } // Se arriviamo qui, // non è stata trovata alcuna tripletta return false; } // Codice driver $A = array (1, 4, 45, 6, 10, 8); $somma = 22; $arr_dimensione = dimensionedi($A); trova3Numeri($A, $dimensione_arr, $somma); // Questo codice è fornito da ajit ?>> |
join e tipi di join
>
>Produzione
Triplet is 4, 8, 10>
Analisi della complessità:
- Complessità temporale: O(N^2), ci sono solo due cicli nidificati che attraversano l'array, quindi la complessità temporale è O(n^2). L'algoritmo a due puntatori richiede tempo O(n) e il primo elemento può essere corretto utilizzando un altro attraversamento nidificato.
- Spazio ausiliario: O(1), poiché non è richiesto spazio aggiuntivo.
Somma tripletta nell'array (somma 3) utilizzando Hashing :
Questo approccio utilizza spazio aggiuntivo ma è più semplice dell'approccio a due puntatori. Esegui due cicli del ciclo esterno dall'inizio alla fine e del ciclo interno da io+1 finire. Crea una mappa hash o un set per memorizzare gli elementi intermedi io+1 A n-1 . Quindi, se la somma data è X, controlla se c'è un numero nel set che è uguale a X – arr[i] – arr[j] . Se sì, stampa la terzina.
Approccio passo dopo passo:
- Scorrere l'array, fissando il primo elemento ( A[i] ) per la terzina.
- Per ciascuno A[i] , usa una Hashmap per memorizzare potenziali secondi elementi che completano la somma desiderata (somma – A[i]) .
- All'interno di un ciclo annidato, controlla se la differenza tra l'elemento corrente ( A[j] ) e la somma desiderata ( somma – A[i] ) è presente nell'Hashmap. Se lo è, viene trovata una tripletta, quindi stampala.
- Se non viene trovata alcuna tripletta nell'intero array, la funzione restituisce falso .
Di seguito è riportata l’implementazione dell’approccio di cui sopra:
C++
#include> using> namespace> std;> // Function to find a triplet with a given sum in an array> bool> find3Numbers(>int> A[],>int> arr_size,>int> sum)> {> >// Fix the first element as A[i]> >for> (>int> i = 0; i // Create a set to store potential second elements // that complement the desired sum unordered_set |
>
>
Giava
import> java.util.HashSet;> public> class> TripletSumFinder {> >// Function to find a triplet with a given sum in an> >// array> >public> static> boolean> >find3Numbers(>int>[] A,>int> arr_size,>int> sum)> >{> >// Fix the first element as A[i]> >for> (>int> i =>0>; i 2; i++) { // Create a HashSet to store potential second // elements that complement the desired sum HashSet s = new HashSet(); // Calculate the current sum needed to reach the // target sum int curr_sum = sum - A[i]; // Iterate through the subarray A[i+1..n-1] to // find a pair with the required sum for (int j = i + 1; j // Calculate the required value for the // second element int required_value = curr_sum - A[j]; // Check if the required value is present in // the HashSet if (s.contains(required_value)) { // Triplet is found; print the triplet // elements System.out.println('Triplet is ' + A[i] + ', ' + A[j] + ', ' + required_value); return true; } // Add the current element to the HashSet // for future complement checks s.add(A[j]); } } // If no triplet is found, return false return false; } public static void main(String[] args) { int[] A = { 1, 4, 45, 6, 10, 8 }; int sum = 22; int arr_size = A.length; // Call the find3Numbers function to find and print // the triplet, if it exists if (!find3Numbers(A, arr_size, sum)) { System.out.println( 'No triplet found with the given sum.'); } } }> |
>
>
Python3
# Function to find a triplet with a given sum in an array> def> find3Numbers(arr,>sum>):> ># Fix the first element as arr[i]> >for> i>in> range>(>len>(arr)>-> 2>):> ># Create a set to store potential second elements that complement the desired sum> >s>=> set>()> ># Calculate the current sum needed to reach the target sum> >curr_sum>=> sum> -> arr[i]> ># Iterate through the subarray arr[i+1:]> >for> j>in> range>(i>+> 1>,>len>(arr)):> ># Calculate the required value for the second element> >required_value>=> curr_sum>-> arr[j]> ># Check if the required value is present in the set> >if> required_value>in> s:> ># Triplet is found; print the triplet elements> >print>(f>'Triplet is {arr[i]}, {arr[j]}, {required_value}'>)> >return> True> ># Add the current element to the set for future complement checks> >s.add(arr[j])> ># If no triplet is found, return False> >return> False> # Driver program to test above function> if> __name__>=>=> '__main__'>:> >arr>=> [>1>,>4>,>45>,>6>,>10>,>8>]> >target_sum>=> 22> ># Call the find3Numbers function to find and print the triplet, if it exists> >if> not> find3Numbers(arr, target_sum):> >print>(>'No triplet found.'>)> |
>
>
C#
using> System;> using> System.Collections.Generic;> class> Program {> >// Function to find a triplet with a given sum in an> >// array> >static> bool> Find3Numbers(>int>[] arr,>int> sum)> >{> >// Fix the first element as arr[i]> >for> (>int> i = 0; i // Create a HashSet to store potential second // elements that complement the desired sum HashSet |
>
function>find3Numbers(A, sum) {>>// Fix the first element as A[i]>>for>(let i = 0; i // Create a Set to store potential second elements that complement the desired sum const s = new Set(); // Calculate the current sum needed to reach the target sum const currSum = sum - A[i]; // Iterate through the subarray A[i+1..n-1] to find a pair with the required sum for (let j = i + 1; j // Calculate the required value for the second element const requiredValue = currSum - A[j]; // Check if the required value is present in the Set if (s.has(requiredValue)) { // Triplet is found; print the triplet elements console.log(`Triplet is ${A[i]}, ${A[j]}, ${requiredValue}`); return true; } // Add the current element to the Set for future complement checks s.add(A[j]); } } // If no triplet is found, return false return false; } function main() { const A = [1, 4, 45, 6, 10, 8]; const sum = 22; // Call the find3Numbers function to find and print the triplet, if it exists if (!find3Numbers(A, sum)) { console.log('No triplet found with the given sum.'); } } // Call the main function to start the program main();>>>ProduzioneTriplet is 4, 8, 10>Complessità temporale: O(N^2)
Spazio ausiliario: O(N), poiché è stato occupato n spazio aggiuntivoPuoi guardare la spiegazione del problema su Youtube discusso dal team Geeks For Geeks.
Puoi anche fare riferimento Questo video presente su Youtube.
Come stampare tutte le terzine con una determinata somma?
Fare riferimento Trova tutte le triplette con somma zero .