rev='made'/> name='keywords'/> name='author'/> ANURANAN: UVa Solution 136 : Ugly Number

Welcome Note

Anisuzzaman Babla

Software Engineer at D Money Bangladesh Limited

I am an enthusiastic Android developer and interested in the newest technologies and trends. I have in total over five years of active Android development experience. I have worked on numerous projects used by hundreds of thousands of people. Moreover, 5+ of commercially successful apps are live at Google play store made by me.

I am eager to learn new things everyday. At the moment, my focus is on the new Java 8 and 9 language features, RxJava and RxAndroid, Kotlin, architectural patterns on Android (MVVM, MVP, etc.) and of course I am always up for trying out the newest Android libraries.

UVa Solution 136 : Ugly Number


#include<stdio.h>
#define s 1501
int main(){
   int p2,p3,p5;
   int ugly[s];
   int a,b,c;
   int i;

  ugly[1]=p2=p3=p5=1;
 
  for(i=2;i<=1500;i++)  {
             a=2*(ugly[p2]);
                b=3*(ugly[p3]);
                c=5*(ugly[p5]);
                if(a<b && a<c){
                  ugly[i]=a;
                  p2++;
                }
                else if(b<a && b<c){
                  ugly[i]=b;
                  p3++;
                }
                else if(c<a && c<b){
                  ugly[i]=c;
                  p5++;
                }

else if(a==b){
                                p3++;
                                i--;
                }
                else if(a==c){
                    p5++;
                                i--;
                }
                else if(b==c){
                  p5++;
                  i--;
                }
  }

  printf("The 1500'th ugly number is %d.\n",ugly[1500]);
  return 0;
}