(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 ...
随机推荐
- Python collections.defaultdict 笔记
其实defaultdict 就是一个字典,只不过python自动的为它的键赋了一个初始值.这也就是说,你不显示的为字典的键赋初值python不会报错,看下实际例子. 比如你想计算频率 frequenc ...
- chroot命令
CHROOT就是Change Root,也就是改变程序执行时所参考的根目录位置.通过chroot机制来更改某个进程所能看到的根目录,即将某进程限制在指定目录中,保证该进程只能对该目录及其子目录的文件有 ...
- 【转】C++ stringstream介绍,使用方法与例子
原文来自:http://www.cnblogs.com/lancidie/archive/2010/12/03/1895161.html C++引入了ostringstream.istringstre ...
- 关于LD_DEBUG (转载)
引用 LD_DEBUGThe dynamic library loader used in linux (part of glibc) has some neat tricks. One of the ...
- MSSQL 如何删除字段的所有约束和索引
原文MSSQL 如何删除字段的所有约束和索引 代码如下: ---------------------------------------------------------- -- mp_DropC ...
- MSSQL SERVER 2008 R2 无法连接到数据库,用户sa登录失败,错误:18456
原因:勾选了强制实施密码策略,但是设置的密码很简单依然可以,比如:123456 这是为什么?原来,这个功能要用到NetValidatePasswordPolicy() API这个函数. (该功能只有在 ...
- Android Studio 新建项目的R文件丢失的解决方法
最近Android Studio炒的比较热,于是笔者决定赶赶时髦,从Eclipse转到了Android Studio.不幸的是,用Android Studio创建项目的时候就遇到了一个比较尖锐的问题— ...
- [Django实战] 第8篇 - 分页列表
当用户登录成功后,首先看到的是他自己之前提交的任务列表,本篇将实现该页面. 视图(views.py)里定义如下: from django.core.paginator import Paginator ...
- probing元素
https://msdn.microsoft.com/zh-cn/library/823z9h8w(v=vs.85).aspx 指定加载程序集时公共语言运行库要搜索的应用程序基子目录. <con ...
- MVC中AuthorizeAttribute用法并实现权限控制
1.创建一个类(用来检查用户是否登录和用户权限)代码如下: public class AuthorizeFilterAttribute: AuthorizeAttribute { //Autho ...