title: Ugly Numbers
signature: class Solution {
  
      public int UglyNumbers(int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  27, 
                  64
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  64, 
                  450
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  93, 
                  1250
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  90, 
                  1152
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  85, 
                  972
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  86, 
                  1000
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  72, 
                  625
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  86, 
                  1000
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  32, 
                  90
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  1, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
source_py: def ugly_numbers(n):
      ugly = ([0] * n)
      ugly[0] = 1
      i2 = i3 = i5 = 0
      next_multiple_of_2 = 2
      next_multiple_of_3 = 3
      next_multiple_of_5 = 5
      for l in range(1, n):
          ugly[l] = min(next_multiple_of_2, next_multiple_of_3, next_multiple_of_5)
          if (ugly[l] == next_multiple_of_2):
              i2 += 1
              next_multiple_of_2 = (ugly[i2] * 2)
          if (ugly[l] == next_multiple_of_3):
              i3 += 1
              next_multiple_of_3 = (ugly[i3] * 3)
          if (ugly[l] == next_multiple_of_5):
              i5 += 1
              next_multiple_of_5 = (ugly[i5] * 5)
      return ugly[(- 1)]
source_cpp: unsigned ugly_numbers(unsigned n) {
    unsigned ugly [ n ];
    unsigned i2 = 0, i3 = 0, i5 = 0;
    unsigned next_multiple_of_2 = 2;
    unsigned next_multiple_of_3 = 3;
    unsigned next_multiple_of_5 = 5;
    unsigned next_ugly_no = 1;
    ugly [ 0 ] = 1;
    for ( int i = 1;
    i < n;
    i ++ ) {
      next_ugly_no = min ( next_multiple_of_2, min ( next_multiple_of_3, next_multiple_of_5 ) );
      ugly [ i ] = next_ugly_no;
      if ( next_ugly_no == next_multiple_of_2 ) {
        i2 = i2 + 1;
        next_multiple_of_2 = ugly [ i2 ] * 2;
      }
      if ( next_ugly_no == next_multiple_of_3 ) {
        i3 = i3 + 1;
        next_multiple_of_3 = ugly [ i3 ] * 3;
      }
      if ( next_ugly_no == next_multiple_of_5 ) {
        i5 = i5 + 1;
        next_multiple_of_5 = ugly [ i5 ] * 5;
      }
    }
    return next_ugly_no;
  }