Problem Statement
This problem is a programming version of Problem 5 from projecteuler.net
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from1 to N ?
Input Format
First line containsT that denotes the number of test cases. This is followed by T lines, each containing an integer, N .
Output Format
Print the required answer for each test case.
Constraints1≤T≤10
1≤N≤40
Sample Input
What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from
Input Format
First line contains
Output Format
Print the required answer for each test case.
Constraints
Sample Input
2
3
10
Sample Output 6
2520
MY SOLUTION:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int fact(int n)
{
int min=1,i,j,a[n];
for(i=0;i<n;i++)
a[i]=i+1;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++){
if((a[j]%a[i])==0)
a[j]=a[j]/a[i];
}
min*=a[i];
}
return min*a[n-1];
}
int main() {
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("%d\n",fact(n));
}
return 0;
}