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 ...
随机推荐
- Linq编程101例
原文地址:101 LINQ Samples in C# Part1 - Restriction Operators Part2 - Projection Operators Part3 - Parti ...
- asp.net中Request.ServerVariables的用法
在asp.net中可以通过HttpRequest.ServerVariables 属性来获取“ Web 服务器变量的集合” HttpRequest.ServerVariables 的用法: HttpR ...
- TSQL Challenge 1
在老外网站发布的一些SQL问题,拿过来自己搞一下,后面我也会陆续转载一些问题,欢迎看到的朋友贴出自己的答案,交流一哈.对于技术问答题的描述,翻译远不不原版来的更好一些,下面我就贴出原版的题目,欢迎参与 ...
- sae crop 文档
原文是google缓存:http://webcache.googleusercontent.com/search?q=cache:MD_FP-G6RI8J:sae.sina.com.cn/%3Fm%3 ...
- JQuery Easy Ui dataGrid 数据表格 ---制作查询下拉菜单
JQuery Easy Ui dataGrid 数据表格 数据表格 - DataGrid 继承$.fn.panel.defaults,使用$.fn.datagrid.defaults重载默认值.. 数 ...
- js中的模块化编写思维
作为一个新手程序员,在编程时一定要刻意锻炼自己的模块化编写思路,但是究竟什么才是模块化编写对于新人来说还是不太能够直观的理解,下面就举个简单的例子来说明一下 概念:最早接触模块化的说法是从java上, ...
- js join()函数将数组转换成字符串
join() 方法用于把数组中的所有元素放入一个字符串.作用是将数组转换为字符串,其作用和toString()相同. 元素是通过指定的分隔符进行分隔的. 例如: var asp=['H','ell', ...
- HTml <meta>标签的使用(重要)
<meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. 1.设置网页字符编码 <meta http-equiv=&q ...
- 弹出层iframe链接设置
jQuery 比较方便就是创建删除了,所以创建一个弹出层就是当点击div的时候创建一个新的div利用固定位fixed(与浏览器窗口有关)和z-index覆盖body 并利用opacity设置其透明度产 ...
- 10个重要的Linux ps命令实战
Linux作为Unix的衍生操作系统,Linux内建有查看当前进程的工具ps.这个工具能在命令行中使用. PS 命令是什么 查看它的man手册可以看到,ps命令能够给出当前系统中进程的快照.它能捕获系 ...