Project Euler__problem 5
来源:互联网 发布:家具软件管理 编辑:程序博客网 时间:2024/05/17 10:57
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?
最小倍数
2520是最小的能够被1到10整除的数。
最小的能够被1到20整除的正数是多少?
这道题目因为我用笔算过,知道它的大概思路
所以趁着今天有空坐下看看能不能解决
首先看看给出的条件2520;
因为有之前做的一道题质因数的经验
我就将他拆分成质因数的乘积
2520=2X2X2X3X3X5X7
所以只需将11-20中的质因数 包含在内即可
x=2 X 2 X 2 X 3 X 3 X 5 X 7 X 11 X 13 X 2 X 17 X 19
但将其转化为计算机语言怎么转化
首先我观察到在10之内都是由质因数的n次方组成
比如2的3次方小于10
3的平方小于10
然后同理 知20的话最大为2的4次方 3的平方 其他质数均为1次方
所以将他们的次方乘积就是所要的结果
#include<iostream>#include<math.h>int zhishu(int num){int a;for (a = num / 2; a > 1; a--)if (num%a== 0)break;else continue;if (a == 1)return 1;else return 0;}int main(){int i;int mul = 1, sq;for (i = 2; i <= 10; i++) if(zhishu(i)!=0){sq = 1;while (sq<10){sq = i*sq;}sq = sq/i;mul = mul*sq;}else continue;std::cout << mul<<"是最小整数"<<std::endl;system("pause");}
把10改为20就可以得到结果232792560
之前尝试用pow但出现错误 原因是pow只能用double类型
阅读全文
0 0
- Project Euler__problem 5
- Project Euler__problem 1
- Project Euler__problem 2
- Project Euler__problem 3
- Project Euler__problem 4
- Project Euler__problem 6
- Project Euler__problem 7
- Project Euler__problem 8
- Project Euler__problem 9
- Project Euler__problem 10
- Project Euler - Problem 5
- Project Euler-5
- Project Euler problem 5
- Problem 5-Project Euter
- Project Euler 5
- Project Euler 1~5
- Project Euler 5
- Mini-project # 5 - Memory
- 重写equals()和hashCode()方法,用于比较对象的内容
- json数据的序列化和反序列化
- Kvm 简介 安装 使用 桥接网络
- 快速删除大量小文件方法
- 计蒜客 17116 Sum(2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C)
- Project Euler__problem 5
- hadoop简介和环境
- Sudo
- 非对称加密 秘钥登录
- Shiro入门学习一
- hadoop local、伪分布 模式
- 秒杀系统(感悟&待续)
- Cacti 邮件 报警
- 移动混合开发,国内镜像及局域网Ionic+Cordova配置