Problem 5

Statement
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 number that is evenly divisible by all of the numbers from 1 to 20?

Solution
The code, in C.

#include <stdio.h>

int div(int a){
  int b,i,j;
  for(i=1;;i++){
    b=1;
    for(j=1;j<=a;j++)
      if(i%j!=0){
	b=0;
	break;
      }
    if(b) return i;
  }
  return 0;
}

int main(void){
  printf("%d\n",div(20));
  return 0;
}

Answer
232792560

No tags for this post.

SPEAK / ADD YOUR COMMENT
Comments are moderated.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>