<MEMORY>Project Euler NO47

最小的两个具有两个不同质数因子的连续整数是:

14 = 2 × 7
15 = 3 × 5

最小的三个具有三个不同质数因子的连续整数是:

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

找出最小的四个具有四个不同质数因子的整数。它们之中的第一个是多少?

时间过长~~

import java.util.Arrays;


public class Problem47
{
	public static void main(String[] args)
	{
		long start = System.currentTimeMillis();
		System.out.print("answer:  ");
		
		howmany();
		
		long end = System.currentTimeMillis();
		System.out.print("time:  ");
		System.out.println(end - start);
	}
	
	static void howmany()
	{
		int array[] = new int[4];
		int yinshu[] = new int[4];
		int nu = 0;
		l1 : for (int i = 14;; i++)
		{
			int t = i;
			int index = 0;
			for (int j = 2; j <= t; j++)
			{
				if (t % j == 0)
				{
					if (index == 0)
					{
						yinshu[0] = j;
						index++;
					}
					else if (j != yinshu[index - 1])
					{
						if (index == 4)
						{
							index = 0;
							continue l1;
						}
						else 
						{
							yinshu[index] = j;
							index++;
						}
					}
					
					t /= j;
					j--;
				}
			}
//			System.out.println(Arrays.toString(yinshu));
			if (index == 4)
			{
				if (nu == 0)
				{
					array[0] = i;
					nu++;
				}
				else if (array[nu - 1] + 1 == i)
				{
					array[nu] = i;
					nu++;
				}
				else 
				{
					array[0] = i;
					nu = 1;
				}
			}
			if (nu == 4)
			{
				System.out.println(Arrays.toString(array));
				break;
			}
		}
	}
}


answer:  [134043, 134044, 134045, 134046]
time:  10189


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值