Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* The problem: 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 by all of the
- numbers from 1 to 20? */
- /* Since non-prime numbers in the range of 11 through 20 are all
- divisible by a number in the range of 2 through 10, only numbers in
- the former range are checked for being factors. Thus, the product of
- these numbers should the maximum checked value. */
- int main()
- {
- long int product = 1;
- int i;
- for(i = 11; i < 21; i++)
- product *= i;
- /* As the biggest factor is 20 and the check starts with 20, the
- step should also be 20. */
- long int checked = 20;
- int interrupted;
- while(checked <= product)
- {
- interrupted = 0;
- for(i = 20; i > 10; i--)
- if(checked % i != 0)
- {
- interrupted = 1;
- break;
- }
- if(interrupted != 1)
- {
- printf("%ld\n", checked);
- break;
- }
- checked += 20;
- }
- return(0);
- }
- /* 232792560 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement