Project Euler:Problem 47 Distinct primes factors
2016-03-07 09:09
316 查看
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?
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; }
相关文章推荐
- two sum
- ios学习笔记(三)多态
- 老梁观世界
- 求链表中环的入口
- 汽车
- 老梁观世界
- 李学斌:论复杂系统中的应用间协作V3
- 数组中重复的数字
- memcached启动脚本
- 视频播放器(AVPlayer)
- 【机器学习学习过程中的笔记1——Stochastic gradient descent 和 Batch gradient descent 】
- TF-IDF及其算法
- myeclipse10 中的UTF-8 设置
- CRC16校验C语言程序源码
- 李学斌:论复杂系统中的应用间协作V3
- UESTC - 1251 谕神的密码 (模拟) 水
- 蓝桥杯-十六进制转八进制
- java中的移位操作
- sql 跨域
- 自我介绍(作业)