Project Euler:Problem 47 Distinct primes factors
The first two consecutive numbers to have two distinct prime factors are:
14 = 2 × 7
15 = 3 × 5
The first three consecutive numbers to have three distinct prime factors are:
644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.
Find the first four consecutive integers to have four distinct prime factors. What is the first of these numbers?
#include <iostream>
#include <map>
using namespace std; int factors(int n)
{
map<int, int>mp;
int i = 2;
while (n > 1)
{
if (n%i == 0)
{
mp[i]++;
n /= i;
}
else
i++;
}
return mp.size();
} int main()
{
for (int i = 20; i <= 1000000; i++)
{
if (factors(i) == 4)
{
if (factors(i + 1) == 4)
{
if (factors(i + 2) == 4)
{
if (factors(i + 3) == 4)
{
cout << i << endl;
break;
}
}
}
}
}
system("pause");
return 0;
}
Project Euler:Problem 47 Distinct primes factors的更多相关文章
- Project Euler:Problem 58 Spiral primes
Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length ...
- Project Euler:Problem 37 Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- Project Euler 47 Distinct primes factors( 筛法记录不同素因子个数 )
题意: 首次出现连续两个数均有两个不同的质因数是在: 14 = 2 × 715 = 3 × 5 首次出现连续三个数均有三个不同的质因数是在: 644 = 22 × 7 × 23645 = 3 × 5 ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- Project Euler:Problem 86 Cuboid route
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...
- Project Euler:Problem 87 Prime power triples
The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...
- Project Euler:Problem 93 Arithmetic expressions
By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...
- Project Euler:Problem 63 Powerful digit counts
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
随机推荐
- xfire找不到services.xml
java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened be ...
- Java Calendar 计算时间差
public static void main(String[] args) { Calendar c=Calendar.getInstance(); int y=2016;//年 int M=1;/ ...
- python正则表达式之使用规则
正则表达式在我看来是提供一个模板,将待匹配的字符串与模板匹配,匹配不到则返回为空,匹配成功根据需要返回匹配的字符串. 正则表达式比字符串本身的功能要强一点,当然性能上略有不如. 我们使用正则 ...
- eclipse慢 优化(转)
1.打开 eclipse.ini -showsplash com.genuitec.myeclipse.product --launcher.XXMaxPermSize 256M -vmargs -D ...
- C#的SerialPort串口程序设计总结
简介:微软的VS提供了SerialPort控件,也就是串行端口资源. 当然也可以添加引用 using System.IO.Ports; 通过实例化SerialPort对象就可以使用其属性和方法了. S ...
- MVC之序列化
1.AdminUserInfo.cs [Serializable]序列化类——System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时 ...
- webservice取文件修改时间,返回1601/1/1 8:00:00
若文件查找不到,则会返回1601/1/1 8:00:00,若能正确查找到该文件,则返回正确的修改时间.
- OOCSS学习(二)
OOCSS —— 面向对象CSS 5.CSS团队精神:CSS最佳团队开发 在本文中,你将学习书写CSS的最佳实践来帮助你避免不一致和冗余;实际上,这样制定标准,简化了团队开发的工作. 1)结构化 (根 ...
- 用python+selenium获取XX省交通违章数据
前言: 目前在研究易信公众号,想给公众号增加一个获取个人交通违章的查询菜单,通过点击返回查询数据.以下是实施过程. 一.首先,用火狐浏览器打开XX省交管网,分析页面信息: 可以看到共有4种查询种类,我 ...
- Razor 语法
Razor 语法 原文:Razor Syntax Reference作者:Taylor Mullen.Rick Anderson翻译:刘怡(AlexLEWIS)校对:何镇汐 什么是 Razor? ...