projecteuler 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整除的最小数。

=======================================

第一次code:

 1 public class Main
 2 {
 3      public static void main (String[] args)
 4      {
 5         System.out.println(sum(600000000));
 6      }
 7      public static int sum(int num)
 8      {
 9       int c=0;
10       for(int i=1;i<num;i++)
11       {
12           if(i % 1== 0 && i % 2 ==0
13           && i % 3== 0 && i % 4 ==0
14           && i % 5== 0 && i % 6 ==0
15           && i % 7== 0 && i % 8 ==0
16           && i % 9== 0 && i % 10 ==0
17           && i % 11== 0 && i % 12 ==0
18           && i % 13== 0 && i % 14 ==0
19           && i % 15== 0 && i % 16 ==0
20           && i % 17== 0 && i % 18 ==0
21           && i % 19== 0 && i % 20 ==0
22                   )
23           {
24               c=i;
25               break;
26           }
27           else
28           {
29               c=111;
30           }
31        }
32        return c;
33      }
34 }
时间: 2024-12-19 07:32:10

projecteuler Smallest multiple的相关文章

Smallest multiple

problem 5:Smallest multiple 题意:求最小的正数,使得其可以被1-20整除 代码如下: 1 #ifndef PRO5_H_INCLUDED 2 #define PRO5_H_INCLUDED 3 4 #include "prime.h" 5 6 namespace pro5{ 7 long long solve(){ 8 long long ans=1; 9 for(int i=2;i<=20;++i) 10 ans=lcm(ans,i); 11 ret

PE5 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? https://projecteuler.net/problem=5 分析 可以将题

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

Project Euler: Solution for Problem 5

Smallest multiple Problem 5 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? Source link: http

PE 001~010

题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的偶数求和. 003(Largest prime factor):求600 851 475 143的最大质因数. 004(Largest palindrome product):求由两个三位数相乘得到的最大回文数. 005(Smallest multiple):求能被1~20中所有数整除的最小正整数.

欧拉计划(python) problem 5

Smallest multiple Problem 5 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? python code : imp

欧拉项目005:最小公倍数

Smallest multiple Problem 5 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 所有数的最

质因数的思维题

Alice and Bob begin their day with a quick game. They first choose a starting number X0?≥?3 and try to reach one million by the process described below. Alice goes first and then they take alternating turns. In the i-th turn, the player whose turn it

OpenCL OpenCL快速入门教程

OpenCL快速入门教程 原文地址:http://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201 翻译日期:2012年6月4日星期一 这是第一篇真正的OpenCL教程.这篇文章不会从GPU结构的技术概念和性能指标入手.我们将会从OpenCL的基础API开始,使用一个小的kernel作为例子来讲解基本的计算管理. 首先我们需要明白的是,OpenCL程序是分成两部分的:一部分是在设备上执行的(对于我们,是GPU),另一部分是