Friday, November 25, 2016

Smallest Multiple


2520 is the smallest number that can be divided by each of the numbers from  to  without any remainder. 
What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from  to ?
Input Format
First line contains  that denotes the number of test cases. This is followed by  lines, each containing an integer, .
Constraints
Output Format
Print the required answer for each test case.
Sample Input 0
2
3
10
Sample Output 0
6
2520
Explanation 0
  • You can check  is divisible by each of , giving quotient of  respectively.
  • You can check  is divisible by each of  giving quotient of  respectively.
NOTE: WRITE YOUR PROGRAM IN COMMENTS SECTION

*************
PROGRAM
************

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int t;
    scanf("%d",&t);
    for(int a0 = 0; a0 < t; a0++){
        int n,count;
        long long max1,max,i;
        scanf("%d",&n);
        max1=n;
        max=n;
        while(1)
        {
            count=0;
            for(i=1;i<=n;i++)
            {
                if(max%i!=0)
                    break;
                count++;
            }
            if(count==n)
                break;
            max+=n;
        }
        printf("%lld\n",max);
    }
    return 0;
}

Contact Form

Name

Email *

Message *