Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. class Solution
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         var r1 = int.Parse(Console.ReadLine());
  6.  
  7.         // Write an action using Console.WriteLine()
  8.         // To debug: Console.Error.WriteLine("Debug messages...");
  9.  
  10.         Console.Error.WriteLine(r1);
  11.  
  12.         Console.WriteLine(calcNbPrec(r1)?"YES":"NO");
  13.     }
  14.    
  15.    
  16.     static bool calcNbPrec(int nombre){
  17.         int i = 1;
  18.         while(i<nombre && nombre != calcNombre(i)){
  19.             i++;
  20.         }
  21.        
  22.         return i<nombre;
  23.     }
  24.    
  25.     static int calcNombre(int nombre){
  26.         var str =""+nombre;
  27.        
  28.         str.ToArray().ToList().ForEach(_=> nombre += int.Parse(""+_));
  29.        
  30.         return nombre;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement