1. 程式人生 > >尤拉計劃 第四十七題

尤拉計劃 第四十七題

The first two consecutive numbers to have two distinct prime factors are:

14 = 2 × 715 = 3 × 5

The first three consecutive numbers to have three distinct prime factors are:

644 = 2² × 7 × 23645 = 3 × 5 × 43646 = 2 × 17 × 19.

Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?

前兩個連續數字有兩個不同的素數因子是:

14 = 2×7 15 = 3×5

前三個連續數字有三個不同的素因子:

644 = 2 2×7×23 645 = 3×5×43 646 = 2×17×19。

找到前四個連續的整數,每個整數有四個不同的素數因子。這些數字中的第一個是什麼?

思路

1.求素因子個數:同尤拉計劃 第十二題

素數篩:如果本身是素數,那只有一個素因子;當i*prime[j] 時,如果 i 能整除prime[j],那麼素因子個數等於i的素因子個數;如果不能整除,加一即可

2.篩選出連續四個素因子個數為4的數字

#include <stdio.h>

#define max 1000000

int prime[max + 5] = {0};
int factor[max + 5] = {0};

int main(){
	for(int i = 2; i < max; i++){
		if(!prime[i]){prime[++prime[0]] = i; factor[i] = 1;}
		for(int j = 1; j <= prime[0]; j++){
			if(i * prime[j] > max) break;
			prime[i * prime[j]] = 1;
			factor[i * prime[j]] = factor[i] + (i % prime[j] != 0);
			if(i % prime[j] == 0) break;
		}
	}
	for(int i = 1; i < max - 3; i++){
		if(factor[i] != 4) continue;
		if(factor[i + 1] != 4) continue;
		if(factor[i + 2] != 4) continue;
		if(factor[i + 3] != 4) continue;
		printf("%d\n",i);
		break;
	}
	return 0;
}

相關推薦

計劃

The first two consecutive numbers to have two distinct prime factors are:14 = 2 × 715 = 3 × 5The first three consecutive numbers to have t

計劃:關於求迴文數。,

第四題:迴文數問題 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 9

計劃

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.低於10的素數之和為2 + 3 + 5 + 7 = 17。找出200萬以

愛創課堂每日一天- 清除浮動的幾種方法?

前端 前端學習 前端入門 1,額外標簽法,<div style="clear:both;"></div>(缺點:不過這個辦法會增加額外的標簽使HTML結構看起來不夠簡潔。) 2,使用after偽類 #parent:after{ content:".

分布式技術追蹤 2017年

微服務 共勉 你是 版本 工作 博士 調度 算法 容器 分布式系統實踐 1. 直擊阿裏雙11神秘技術:PB級大規模文件分發系統“蜻蜓” https://mp.weixin.qq.com/s/J0O4jD0d4jCjU56wpEJu1w 摘要: 2017天貓雙11, 交易峰值

mysql 篇文章~mysql優化之相關join

讓我 復雜 文章 進行 order by 算法 char 出現 而是 一簡介:參考了幾位師兄,尤其是M哥大神的博客,讓我恍然大悟,趕緊記錄下二 原理: mysql的三種算法 1 Simple Nested-Loop Join 將驅動表/外部表的結果集作為循環基礎數據,然後

【leetcode 簡單】 兩數之和 II - 輸入有序數組

nbsp def art col else ber clas 不可 strong 給定一個已按照升序排列 的有序數組,找到兩個數使得它們相加之和等於目標數。 函數應該返回這兩個下標值index1 和 index2,其中 index1 必須小於 index2。 說明: 返

【leetcode 簡單】 階乘後的零

時間 時間復雜度 ron elf 說明 輸入 數量 n) 復雜度 給定一個整數 n,返回 n! 結果尾數中零的數量。 示例 1: 輸入: 3 輸出: 0 解釋: 3! = 6, 尾數中沒有零。 示例 2: 輸入: 5 輸出: 1 解釋: 5! = 120, 尾數中有 1

【leetcode 簡單】 兩整數之和

turn div 計算 pre lee nbsp gets tco shu 不使用運算符 + 和-,計算兩整數a 、b之和。 示例: 若 a = 1 ,b = 2,返回 3。 class Solution: def getSum(self, a, b):

【leetcode 簡單】 快樂數

col 快樂數 如果 表示 else color tco span str 寫一個程序,輸出從 1 到 n 數字的字符串表示。 1. 如果 n 是3的倍數,輸出“Fizz”; 2. 如果 n 是5的倍數,輸出“Buzz”; 3.如果 n 同時是3和5的倍數,輸出 “Fiz

計劃問題matlab實現

Problem4: Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numb

C++筆記 課 父子間的衝突---狄泰學院

如果在閱讀過程中發現有錯誤,望評論指正,希望大家一起學習,一起進步。 學習C++編譯環境:Linux 第四十七課 父子間的衝突 1.思考 子類中是否可以定義父類中的同名成員?如果可以,如何區分?如果不可以,為什麼? 47-1 同名成員變數 #include<io

講 I/O流——常用IO流(列印流、合併流、序列流、隨機訪問流以及管道流)

列印流 列印流即輸出流,分為位元組列印流PrintStream和字元列印流PrintWriter。下面分別對它們進行介紹。 位元組列印流 概述 PrintStream為其他輸出流添加了功能,使它們能夠方便地列印各種資料值表示形式。它還提供其他兩項功能。與其他輸出流不同,P

“全棧2019”Java章:繼承與方法

難度 初級 學習時間 10分鐘 適合人群 零基礎 開發語言 Java 開發環境 JDK v11 IntelliJ IDEA v2018.3 文章原文連結 “全棧2019”Java第四十七章:繼承與方法 下一章 “全棧2019”Java第四十八章:重寫方法Override

計劃問題二的matlab實現

Problem 20 : Factorial digit sum n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the s

孤荷凌寒自學python天通用跨資料庫同一資料庫中複製資料表函式

孤荷凌寒自學python第四十七天通用跨資料庫同一資料庫中複製資料表函式   (完整學習過程螢幕記錄視訊地址在文末) 今天繼續建構自感覺用起來順手些的自定義模組和類的程式碼。 今天打算完成的是通用的(至少目前操作四種資料庫)在同一資料庫內複製資料表的方法函式。   此設想最初我

章:Linux基礎命令

Linux基礎命令 背景知識 Linux系統中一切皆檔案 在Linux系統中任何東西都是以檔案形式來儲存的。這其中不僅包括我們熟知的文字檔案、可執行檔案等等,還包括硬體裝置、虛擬裝置、網路連線等等,甚至連目錄其實都是一種特殊的檔案。 Linux檔案系統 Linux系統環境下的檔案

java學習之路——---一天

前段時間,這個坑公司又把網給斷了,所以就一直沒發,今天把之前的都發一下吧,請允許我複製。。。。 12.27:連線池 一、資料庫連線池:          為什麼要連線池技術?   &n

Gradle 1.12使用者指南翻譯——章. Build Init 外掛

本文由CSDN部落格貌似掉線翻譯,其他章節的翻譯請參見:http://blog.csdn.net/column/details/gradle-translation.html翻譯專案請關注Github上的地址:https://github.com/msdx/gradledoc

《劍指offer》(序列化二叉樹)

nbsp pre 三十七 === eof istream node nod style // 面試題37:序列化二叉樹 // 題目:請實現兩個函數,分別用來序列化和反序列化二叉樹。 #include "BinaryTree.h" #include <io