(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 ...
随机推荐
- (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 ...
- BootStrap学习2 typeahead
首先看看这些 http://www.wrapcode.com/bootstrap/typeahead-json-objects/ http://stackoverflow.com/questions/ ...
- 帝国cms灵动标签下常用标签
这里简单整理下灵动标签下的常用标签 标题名称:<?=$bqr['title']?> <?=esub($bqr[title],22)?> 限制字符22个 标题链接:<?= ...
- 基于Visual C++2013拆解世界五百强面试题--题17-程序结果分析1
分析程序结果,分析过程我们就写在程序注释里面. 写出下列代码的输出内容 #include <stdio.h> int inc(int a) { return (++a); } int mu ...
- HDU 1286 找新朋友
题解:分析题目,就是一个裸的欧拉函数,于是AC. #include <cstdio> int eular(int n){ int ret=1,i; for(i=2;i*i<=n;i+ ...
- Java学习之DAO设计模式
DAO设计模式是一个javaEE里的设计模式,DAO是Data Access Object 数据访问接口. 一个典型的DAO实现有三个组件: 1.一个DAO接口 2.一个DAO接口的具体类: 3.数据 ...
- installation - How to install Synaptic Package Manager? - Ask Ubuntu
installation - How to install Synaptic Package Manager? - Ask Ubuntu How to install Synaptic Package ...
- selenium - Headless Browser and scraping - solutions - Stack Overflow
yum install pygtk2-devel selenium - Headless Browser and scraping - solutions - Stack Overflow Hea ...
- CSS3媒体查询(Media Queries)
媒体类型: all 所有设备 screen 电脑显示器 handheld 便携设备 tv 电视类型设备 print 打印用纸打印预览视图 关键字 and not(排除某种设备) only(限定某种设备 ...
- Linux-中断和中断处理
1.中断 #中断使得硬件得以发出通知给处理器,本质上是一种电信号 #中断随时能够产生.内核随时会被打断 #不同设备的中断不同,每一个中断都通过一个唯一的数字标识.称为IRQ(中断请求) 2.中断处理程 ...