To generate numbers of the form 2^i * 3^j * 5^k

Submitted by:Jessey Ryder

Date added:19 January, 2011

Category:C

To generate numbers of the form 2^i * 3^j * 5^k

Tags: matrix , generate array

Code Snippet:

#include <stdio.h>
#include <stdlib.h>

#define MAX 20000
#define MAX_ITER 2000

long long int A[MAX];

int main()
{
int i,j,k;
long long int global_min,n;


A[0]=1;
A[1]=2;
A[2]=3;
A[3]=4;
A[4]=5;

i=5;

while(1)
{
global_min=1e17;
n=-1;

for(j=0 ; j<i ; j++)
{
for(k=0 ; k<i ; k++)
{
n=A[j]*A[k]; // USING PREVIOUS VALUES -- LESS EFFICIENT BUT ANOTHER APPROACH USING DP
if(n>A[i-1] && n<global_min)
global_min=n;
}
}

A[i]=global_min;
printf("%d : %lld\n",i++,global_min);

if((i-1)%100==0)
sleep(1); // sleep used for human to view output
}

return 0;
}
 
 

Comments