Problem5-Project Euler
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?
考虑质因数分解,将1-20都分解,挑质因数的最高幂次相乘即可。
#include"stdio.h"
#include"math.h" #define N 20 int prime[N+]; int find_prime(int x)
{
int i,j,sum=;
for(i=;i<=x;i++)
{
prime[i]=;
for(j=;j<=int(sqrt(i));j++)
if(i%j==)
prime[i]=;
if(prime[i]!=&&i>=)
{
prime[i]=int(log(x)/log(i));
sum *= int(pow(i,prime[i]));
}
}
return(sum);
} int main() /*problem5-smallest multiple*/
{
printf("answer is %d\n",find_prime(N));
return();
}
Problem5-Project Euler的更多相关文章
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【Project Euler 8】Largest product in a series
题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...
- Project Euler 第一题效率分析
Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...
- Python练习题 049:Project Euler 022:姓名分值
本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
- Python练习题 047:Project Euler 020:阶乘结果各数字之和
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial ...
随机推荐
- Linq 多表连接查询join
在查询语言中,通常需要使用联接操作.在 LINQ 中,可以通过 join 子句实现联接操作.join 子句可以将来自不同源序列,并且在对象模型中没有直接关系(数据库表之间没有关系)的元素相关联,唯一的 ...
- .gvimrc配置备份
syn on "语法支持 colorscheme murphy set go= "common conf {{ 通用配置 "set ai "自动缩进 set b ...
- Apache 源码安装
8.20]# make[root@yahoo pcre-8.20]# make install 二.安装apache1.下载httpd-2.4.3.tar.gz,地址是:http://httpd.ap ...
- vuex数据管理-数据模块化
对于vue这类mvvm框架来说,其核心就是组件与数据,因此做好相应的数据管理极为重要.这里分享下vuex数据模块化管理的方法,有利于搭建便于维护.协作的vue项目. vuex管理基本方法和使用 模块化 ...
- es6学习笔记2-—symbol、变量与作用域
1.新的字符串特性 标签模板: String.raw(callSite, ...substitutions) : string 用于获取“原始”字符串内容的模板标签(反斜杠不再是转义字符): > ...
- Git学习笔记4
现在,远程库已经准备好了,下一步是用命令git clone克隆一个本地库: $ git clone git@github.com:michaelliao/gitskills.git 要克隆一个仓库,首 ...
- vue-cli + element-ui + webpack 新建项目
1.进入项目目录 2.全局安装vue-cli 输入命令:npm install vue-cli -g 若报错:ENOENT: no such file or directory, access.... ...
- ASP.NET MVC显示UserControl控件(扩展篇)
昨晚Insus.NET有怀旧一下<念念不忘,ASP.NET MVC显示WebForm网页或UserControl控件>http://www.cnblogs.com/insus/p/3641 ...
- Win10 注册IIs4.0的解决方案
随着Win10的出现,越来越多的人装上了Win10,尤其是程序员,由于Win10是一个新的操作系统,但现有软件的兼容性等各方面都是未知,难免会存在很多坑,就拿IIS来说,我刚装完win10系统,然后装 ...
- Java JDBC的基础知识(四)
之前学习了如何创建一个数据库工具类,如下: import java.sql.Connection; import java.sql.DriverManager; import java.sql.Res ...