题目链接

题目:

125874和它的二倍,251748, 包含着同样的数字,只是顺序不同。

找出最小的正整数x,使得 2x, 3x, 4x, 5x, 和6x都包含同样的数字。

这个题目相对比较简单

暴力遍历

判断x,2x,3x,4x,5x,6x是否包含的数字相同

如何判断两个数包含的数字相同?

1.

两个数字转换成字符串后:d1,d2

定义两个集合ts1,ts2,

将d1,d2的各位数都添加到集合ts1中

将d1的各位数添加到集合ts2中

最后这个两个集合相等,则,这个两个数包含相同的数字

2.

public  boolean permutation(int a, int b)
{
int[] nums = new int[10];
int temp1 = a;
int temp2 = b;
while(temp1>0 && temp2>0)
{
nums[temp1%10]++;
nums[temp2%10]--;
temp1/=10;
temp2/=10;
}
for(int c = 0;c<10;c++)
{
if(nums[c] != 0)
return false;
}
return true;
}

看程序吧,描述不好了。。。

java程序:

package projecteuler51to60;

import java.util.Set;
import java.util.TreeSet; class level52{
void solve0(){
int Max_Value=1000000; for(int i=2;i<Max_Value;++i){
if(sameDigit(i,2*i) &&sameDigit(i,3*i) &&
sameDigit(i,4*i) &&sameDigit(i,5*i) &&
sameDigit(i,6*i)){
System.out.println(i);
return;
}
} }
void solve1(){
int orig=1;
int ans=0;
while(ans==0){
int count=1;
for(int a=2;a<=6;a++){
int b=orig*a;
if(permutation(orig,b))
count++;
}
if(count==6)
ans=orig;
orig++;
}
System.out.println(ans);
}
public boolean permutation(int a, int b)
{
int[] nums = new int[10];
int temp1 = a;
int temp2 = b;
while(temp1>0 && temp2>0)
{
nums[temp1%10]++;
nums[temp2%10]--;
temp1/=10;
temp2/=10;
}
for(int c = 0;c<10;c++)
{
if(nums[c] != 0)
return false;
}
return true;
} boolean sameDigit(int a,int b){
String stra=String.valueOf(a);
String strb=String.valueOf(b);
Set<String> set=new TreeSet<String>();
Set<String> setEqual=new TreeSet<String>();
if(stra.length()!=strb.length()) return false;
for(int i=0;i<stra.length();i++){
set.add(stra.substring(i,i+1));
set.add(strb.substring(i,i+1));
setEqual.add(strb.substring(i,i+1)); }
return set.equals(setEqual);
} }
public class Problem52 { public static void main(String[] args){
long begin= System.currentTimeMillis();
new level52().solve0();
long end = System.currentTimeMillis();
long Time = end - begin;
System.out.println("Time:"+Time/1000+"s"+Time%1000+"ms");
} }

欧拉工程第52题:Permuted multiples的更多相关文章

  1. 欧拉工程第69题:Totient maximum

    题目链接 欧拉函数φ(n)(有时也叫做phi函数)可以用来计算小于n 的数字中与n互质的数字的个数. 当n小于1,000,000时候,n/φ(n)最大值时候的n. 欧拉函数维基百科链接 这里的是p是n ...

  2. 欧拉工程第70题:Totient permutation

    题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...

  3. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  4. 欧拉工程第66题:Diophantine equation

    题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...

  5. 欧拉工程第65题:Convergents of e

    题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...

  6. 欧拉工程第56题:Powerful digit sum

    题目链接   Java程序 package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; im ...

  7. 欧拉工程第55题:Lychrel numbers

    package projecteuler51to60; import java.math.BigInteger; import java.util.Iterator; import java.util ...

  8. 欧拉工程第54题:Poker hands

    package projecteuler51to60; import java.awt.peer.SystemTrayPeer; import java.io.BufferedReader; impo ...

  9. 欧拉工程第53题:Combinatoric selections

    package projecteuler51to60; class p53{ void solve1(){ int count=0; int Max=1000000; int[][] table=ne ...

随机推荐

  1. 条款3:尽可能地使用const

    如下为const修饰的几种类型: char name[] = "benxintuzi"; char* p1 = name;                // non-const ...

  2. MVC Razor模板引擎输出HTML或者生产HTML文件

    以前做CMS的时候都会根据模板来生成输出HTML或者生成HTML文件. 常用的引擎有VTemplate.NVelocity等等,这个我就布做介绍了. 这里我想说的是.当mvc出现Razor模板引擎的时 ...

  3. 如何安装altium designer 10

    http://jingyan.baidu.com/article/4dc4084881e2bdc8d946f1f3.html

  4. 2.Modelsim打开时出现的Error

    Modelsim之error “unable to check out a viewer license necessary for use of the modelsim graph.Vsim is ...

  5. UIDatePicker swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  6. HTML5就是现在:深入了解Polyfills

    http://blog.csdn.net/wang16510/article/details/8960312 https://github.com/Modernizr/Modernizr/wiki/H ...

  7. cocos2dx中的场景和使用方法

    1.一个游戏中有且只有一个导演,但是至少有一个场景 2.场景是游戏元素节点数的根节点,也可以理解为该场景下的渲染树的根节点 3.场景是一个容器,包含了该场景下的所有游戏元素,比如层,精灵 4.场景是导 ...

  8. Android开发随笔1

    由于对Android的不了解所以上网看视频学习 昨天: 配置安卓的开发环境,一开始想直接在www.android.com里下载相应的sdk工具整合包后来因为需要越墙便跟从同学那里要了一份sdk 装jd ...

  9. iptables端口转发

    iptables -t nat -A PREROUTING -d {外网ip}/32 -p tcp -m tcp --dport 4956 -j DNAT --to-destination 10.1. ...

  10. SGU 185 Two shortest 最短路+最大流

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21068 Yesterday Vasya and Petya qua ...