(Problem 5)Smallest multiple
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 <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h> #define N 20 int gcd(int a, int b)
{
if(b==)
return a;
else
return gcd(b,a%b);
} int lcm(int a, int b)
{
return a/(gcd(a,b))*b;
} void solve()
{
int i,s=;
for(i=; i<=N; i++)
{
s=lcm(s,i);
}
printf("%d\n",s);
} int main()
{
solve();
return ;
}
Answer:
|
232792560 |
(Problem 5)Smallest multiple的更多相关文章
- (Problem 46)Goldbach's other conjecture
It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (Problem 74)Digit factorial chains
The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...
- (Problem 72)Counting fractions
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 53)Combinatoric selections
There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
随机推荐
- poj 1410 计算几何
/** 注意: 千万得小心..就因为一个分号,调了一个晚上... **/ #include <iostream> #include <algorithm> using name ...
- 精简版LVCL,有空看看
http://tothpaul.free.fr/sources.php?lvcl.lvcl1 http://synopse.info/forum/viewtopic.php?id=665
- HDU 2501 Tiling_easy version
递推式:f[n]=2*f[n-2]+f[n-1] #include <cstdio> #include <iostream> using namespace std; ]; i ...
- Oracle 存储过程DEMO
); cursor isbns is select ISBN,id from librarys; bn isbns%rowtype; begin for bn in isbns loo ...
- JAVA FILE or I/O学习 - Desktop本地程序学习
public class DesktopKnow { public void know() { try { Desktop.getDesktop().open(new File("C:\\P ...
- 【Java线程】Lock、Condition
http://www.infoq.com/cn/articles/java-memory-model-5 深入理解Java内存模型(五)——锁 http://www.ibm.com/develope ...
- zoj 3656 2-sat 不错的题
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4879 TLE了一下午.然后没办法了 去搜题解 发现思路跟我的差点儿相同 可是 ...
- css中的滤镜
前几天在做一个app应用的时候,用到了滤镜.在之前我只是知道有这么个东西,但是具体的知识点其实我是不太清楚的,所以为了让自己能深刻记忆,专门把它来记录一下.. 一.滤镜的标识符:“filter”;语法 ...
- ORACLE分科目统计每科前三名的学生的语句
有个成绩表 score(student_no,Subject_no,Score)分别为学号,课程号,成绩.我想用语句查询出每科的前三名学生的学号,请各位高手教教小弟 1.创建测试语句:create t ...
- use MSBuild cmd to build and deploy the database project.
You can use the below command to implement it. SET TargetDBName="Database name" SET DataBa ...