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 ...
随机推荐
- Linq101-Restriction
using System; using System.Linq; namespace Linq101 { class Restriction { /// <summary> /// Thi ...
- ASP.NET5 静态文件
静态文件,包括HTML文件,CSS文件,图像文件和JavaScript文件,它是一个应用里所包含的资源. 1. 提供静态文件 默认的,静态文件存储在你的webroot目录下面,webroot的路径定义 ...
- MIME协议
转:http://blog.csdn.net/flfna/article/details/5048290 MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候 ...
- Android开发手记(20) 数据存储五 网络存储
Android为数据存储提供了五种方式: 1.SharedPreferences 2.文件存储 3.SQLite数据库 4.ContentProvider 5.网络存储 安卓的网络存储比较简单,因为A ...
- Java study 1:The note of studying Socket which based UDP
UDP concept: UDP 是User Datagram Protocol的简称, 中文名是用户数据报协议,是OSI(Open System Interconnection,开放式系统互联) 参 ...
- centos 用户切换
在系统的/etc/.bash_profile中已经配置了各种环境变量. 用账户a登陆,ldd xxx.so查看一切链接正常. 用账户root登陆,ldd xxx.so查看一切链接正常. 用账户a登陆, ...
- Bit Map解析
1. Bit Map算法简介 来自于<编程珠玑>.所谓的Bit-map就是用一个bit位来标记某个元素对应的Value, 而Key即是该元素.由于采用了Bit为单位来存储数据,因此在存储空 ...
- 安装 mysql
1.安装mysql客户端 yum install mysql 2.安装mysql 服务器端 yum install mysql-server 3.配置 mysql字符集 /etc/my.cnf 加入 ...
- 用jquery修改默认的单选框radio或者复选框checkbox选择框样式
默认的radio和checkbox选框很难看.我去看了一下qq注册的页面.发现单选和复选框并没有用<input>,居然是用是A标签.然后用css背景图片展示选择框,用JavaScript控 ...
- js中callee与caller的区别
callee是对象的一个属性,该属性是一个指针,指向参数arguments对象的函数首先我们来写个阶成函数:function chen(x){if (x<=1) {return 1;} else ...