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 ...
随机推荐
- SpringBoot用@ConfigurationProperties获取配置文件值
SpringBoot的配置文件有yml和properties两种,看一些文章说yml以数据为中心,比较好.个人觉得properties更好用,所以这里以properties格式为例来说. 我们都知道@ ...
- docker 非root用户修改mount到容器的文件出现“Operation not permitted
使用环境centos7 x86-64 内核版本4.19.9 docker使用非root用户启动,daemon.json配置文件内容如下: # cat daemon.json { "usern ...
- fastjson 处理 double 的精度问题
项目中使用 fastjson 来处理 json 格式,当前使用的版本为1.1.37.在和其它系统交互时,将一个json串传给了对方,原值为5.0,json 处理后格式为:{"dou" ...
- C++函数中返回引用和返回值的区别
一.主要讨论下面两个函数的区别: int& at() { return m_data_; } int at() { return m_data_; } 上面两个函数,第一个返回值是int的引用 ...
- java8 Stream使用案例
1. 原理 Stream 不是集合元素,它不是数据结构并不保存数据,它是有关算法和计算的,它更像一个高级版本的 Iterator. 原始版本的 Iterator,用户只能显式地一个一个遍历元素并对其执 ...
- Eclipse 处理 IOConsole Updater 报错
上篇博文说了如何处理 Eclipse Console打印不自动删除问题, 而不让日志自动删除后会报错:IOConsole Updater 重复的刷屏,一会之后,就会出现IOConsole Update ...
- webpack4 自学笔记三(提取公用代码)
全部的代码及笔记都可以在我的github上查看, 欢迎star:https://github.com/Jasonwang911/webpackStudyInit/tree/master/commonT ...
- unity 中Canvas MatchHeight
设置了 UI Scale Mode = Scale With Screen Size, Reference Resolution = X 1334, Y 750, Screen Match Mode ...
- 在Android开发中替换资源图片不起作用的解决方法
现象 在android开发中,经常会需要替换res\drawable中的图片,打开res\layout下的文件预览布局页面发现图片已经被替换,但在模拟器或者真实机器上运行时发现该图片并没有被替换,还是 ...
- Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#
原文链接地址: http://csharpindepth.com/Articles/General/Singleton.aspx#unsafe Implementing the Singleton P ...