/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        E T U D E   D E   L A   P E R S I S T A N C E   A D D I T I V E   D E S   N O M B R E S  :                                 */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xtc/PersistanceAdditive.11$c' :                                                                                */
/*                                                                                                                                   */
/*                    Jean-Francois COLONNA (LACTAMME, 20130602085923).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#include  "INCLUDES.01.I"

#define   BASE      10

#define   N1        1
#define   N2        999

main()
          {
          int       NombreCourant;
          int       PersistanceMaximale=-1;

          for       (NombreCourant=N1 ; NombreCourant<=N2 ; NombreCourant++)
                    {
                    int       Reduction=NombreCourant;
                    int       Persistance=0;

                    printf("%d",NombreCourant);

                    while     (Reduction >= BASE)
                              {
                              int       Cumul=0;
                              int       Quotient=Reduction;
                              int       Reste;

                              while     (Quotient != 0)
                                        {
                                        Reste = Quotient%BASE;
                                        Quotient = Quotient/BASE;
                                        Cumul = Cumul+Reste;
                                        }

                              Reduction = Cumul;

                              printf(" --> %d",Reduction);
                              Persistance++;
                              }

                    PersistanceMaximale=MAX2(PersistanceMaximale,Persistance);
                    printf("     p=%d (base=%d)\n",Persistance,BASE);
                    }

          printf("PersistanceMaximale=%d\n",PersistanceMaximale);
          }



Copyright © Jean-François COLONNA, 2021-2024.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / École polytechnique, Institut Polytechnique de Paris, 2021-2024.