Ugly Number ||


  • 0
    S

    #include<stdio.h>
    int main()
    {
    int ara[100000];
    int ara2[100000];
    int ara3[100000];
    int i,j,k=0,n,m,a=0,sum=0;
    int b=0;
    inn: scanf("%d%d", &m,&n);
    if(m<n)
    goto inn;
    else{
    for(i=1; i<=m; i++){
    for(j=1; j<=m; j++){
    if(i%j==0)
    k++;
    }
    if(k==2){
    ara[a++]=i;///Accessing the prime numbers into Array1...
    sum++;///Counting the elements of Array1...
    }
    k=0;

    }
    

    for(i=3; i<m; i++){

    ara2[b++]=ara[i];///Accessing the prime numbers(without 2,3,5) into Array2..
    

    }

    int l=0,r=0;
    for(i=1; i<=m; i++){
    for(j=0; j<sum-3; j++){
    if(i%ara2[j]==0)///If other elements abide by this condition, then we shall get the Ugly NUmbers..

            l++;
    
    
    }
    if(l<1)
        ara3[r++]=i;
    l=0;
    

    }

    for(i=1; i<=n; i++){
            if(i!=n){  ///This is used for printing comma..
        printf("%d, ", ara3[i-1]);
            }
             else if(i==n)///This is used for ignoring comma for thr last element of Ugly Number...
             {
    
    
             printf("%d ",ara3[i-1]);///Now, This is a code of Ugly Number done...
             }
    }
    }
    

    return 0;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.