(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 ...
随机推荐
- monkeyrunner学习--手机按键
按下HOME键 device.press('KEYCODE_HOME','DOWN_AND_UP') 按下BACK键 device.press('KEYCODE_BACK','DOWN_AND_UP' ...
- QT小技巧—更好管理项目(增加预编译头文件,并且指定moc文件的生成位置)good
预编译加速编译 QT也可以像VS那样使用预编译头文件来加速编译器的编译速度.首先在.pro文件中加入: CONFIG += precompiled_header 然后定义需要预编译的头文件: PREC ...
- 基于Visual C++2013拆解世界五百强面试题--题9-找出所有的排列方式
给出一个函数来输出一个字符串的所有排列 按照排列组合的知识我们知道 N个字符排列组合个数有n!种, 那么可知f(n) = n*f(n-1), 如果{1,2}的组合有两种,12,21, 那么{123}的 ...
- Noip2010提高组总结
将Noip2010重新做了一遍,第一遍做下来居然只有290分,比当年浙江的一等线低了20分,因为各种坏习惯丢掉了许多分数,Noip时需要特别注意! T1:机器翻译 第一题直接暴力,内存足够所以不用循环 ...
- HDU 2178 猜数字
题解:设猜到的最大的数是h,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1. #include <cstdio& ...
- poj 1077 Eight(双向bfs)
题目链接:http://poj.org/problem?id=1077 思路分析:题目要求在找出最短的移动路径,使得从给定的状态到达最终状态. <1>搜索算法选择:由于需要找出最短的移动路 ...
- Java集合框架的知识总结
说明:面试准备,写的挺不错的. 转载地址: http://www.cnblogs.com/zhxxcq/archive/2012/03/11/2389611.html 1.综述 所有集合类都位于jav ...
- flex正则表达式
正则表达式是一种通用的标准,大部分计算机语言都支持正则表达式,包括as3,这里收集了一些常用的正则表达式语句,大家用到的时候就不用自己写了 ^\d+$ //匹配非负整数(正整数 + 0) ^[0-9] ...
- Python学习入门基础教程(learning Python)--2.2.1 Python下的变量解析
前文提及过变量代表内存里的某个数据,这个说法有根据么? 这里我们介绍一个python内建(built-in)函数id.我们先看看id函数的帮助文档吧.在python查某个函数的帮助文档很简单,只用he ...
- 页面布局之BFC 微微有点坑
一.什么是BFC: 在解释 BFC 是什么之前,需要先介绍 Box.Formatting Context的概念. Box: CSS布局的基本单位 Box 是 CSS 布局的对象和基本单位, 直观点来说 ...