(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?
题目大意:
最小的两个具有两个不同质数因子的连续整数是:
14 = 2
7 15 = 3
5
最小的三个具有三个不同质数因子的连续整数是:
644 = 2²
7
23 645 = 3
5
43 646 = 2
17
19.
找出最小的四个具有四个不同质数因子的连续整数。它们之中的第一个是多少?
//(Problem 47)Distinct primes factors
// Completed on Thu, 13 Feb 2014, 12:50
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/ #include<stdio.h>
#include<stdbool.h> int a[]; bool prim(int n)
{
int i;
for(i = ; i * i <= n; i++) {
if(n % i == ) return false;
}
return true;
} void init()
{
int i,j;
i = ;
j = ;
a[] = ;
while(j < ) {
if(prim(i)) a[j++] = i;
i += ;
}
} bool judge(int n)
{
int i, flag, count;
count = flag = ; for(i = ; i < ; i++) {
while(n % a[i] == ) {
flag = ;
n = n / a[i];
}
if(flag) count++;
flag = ;
if(count == ) return true;
}
return false;
} void solve()
{
int i;
for(i = ; i < ;) {
if(judge(i)) {
if(judge(i + )) {
if(judge(i + )){
if(judge(i + )){
printf("%d %d %d %d\n", i, i + , i + , i + );
return;
} else {
i += ;
continue;
}
} else {
i += ;
continue;
}
} else {
i += ;
continue;
}
} else {
i++;
}
}
} int main()
{
init();
solve();
return ;
}
|
Answer:
|
134043 |
(Problem 47)Distinct primes factors的更多相关文章
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
- (Problem 29)Distinct powers
Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...
- (Problem 53)Combinatoric selections
There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- (Problem 33)Digit canceling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- (Problem 73)Counting fractions in a range
Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...
- (Problem 42)Coded triangle numbers
The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...
- (Problem 41)Pandigital prime
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
随机推荐
- m文件转换为C/C++文件的编译、绘图、参数、打包问题总结
在工程计算相关项目中,常常利用Matlab来完成计算.算法.绘图等功能.使用Matlab来完成这些功能非常简单,Matlab提供的m编程语言功能强大,代码量少.为了在自己的C/C++项目中加入这些功能 ...
- Ubuntu下lamp(PHP+Mysql+Apache)搭建+完全卸载卸载方法
安装apache2 sudo apt-get install apache2 安装完成,运行如下命令重启下: sudo /etc/init.d/apache2 restart 在浏览器里输入http: ...
- 网页在Safari快速滚动和回弹的原理: -webkit-overflow-scrolling : touch;的实现
现在很多for Mobile的H5网页内都有快速滚动和回弹的效果,看上去和原生app的效率都有得一拼. 要实现这个效果很简单,只需要加一行css代码即可: -webkit-overflow-scrol ...
- 一个简单的文本编辑器。(是在DEV C++下写的)
//头文件// main.h #define CM_FILE_SAVEAS 9072 #define CM_FILE_EXIT 9071 #define CM_FILE_OPEN 9070 #defi ...
- linux之iptable案例
转自:http://blog.csdn.net/bill_lee_sh_cn/article/details/4401896 1.一对一流量完全DNAT 首先说一下网络环境,普通主机一台做防火墙用,网 ...
- 转载ajax
写在前面的话: 用了很久的Asp.Net Ajax,也看了段时间的jquery中ajax的应用,但到头来,居然想不起xmlHttpRequest的该如何使用了. 以前记的也不怎么清楚,这次就重新完整的 ...
- Clementine 12.0 的使用(因为比较少用,项目中用到才开始接触写一下自己的使用方法)
首先我是根据excel的文件做的训练,就以excel来做介绍 1.打开Clementine 12.0 软件 点击软件下方的 ”源“ 即你要做训练的数据源.因为是excel文件双击excel. 2.双击 ...
- 多个viewpager可能产生的问题
由于Fragment的方便性,现在很多人开始大量使用Fragment. 今天使用时遇到各问题,记录下来并分享下. 使用Fragment都会用FragmentActivity ,特别是在用到ViewPa ...
- Linux字符界面和图形界面
Ubuntu图形界面和字符界面的切换 Ubuntu和其他的Linux系统一样,有图形界面和字符界面,同时能够设置默认的启动界面. linux的显示界面分为命令行的字符界面和图形界面,我们可以设置lin ...
- 我用过的Linux命令--关闭防火墙
关闭防火墙: 防火墙的弄能是限制某一些端口的使用,可以通过linux命令关系它,相应的指令: 查看防火墙信息: #service iptables status 就能看到防火墙的状态: 关闭防火墙: ...