project euler problem 5:Smallest multiple

Problem 5

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?

这个有点像求素数一样,挺简单的……

#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int cmp(int a)
{
    int i;
    for(i=2;i<=20;i++)
        if(a%i) return 0;;
    return 1;
}
int main()
{
    int i;
    for(i=2521;;i++)
        if(cmp(i))
        {
            cout<<i<<endl;
            break;
        }
    return 0;
}

你可能感兴趣的:(project euler problem 5:Smallest multiple)