题目链接

题目:

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. ASP.NET MVC中使用事务写法

    一些项目中,会涉及到事务的写法,比如订单相关,订单成功,会涉及到产品的库存和账户金额的一些信息变动,当然,如果整个流程成功,那是没什么问题,关键是如果中间某一步骤出现bug了,那之前已执行的一些变动就 ...

  2. pb对Web Service的操作可使用两种方式实现

    从PB8.0/9.0开始,就已经提供Web Service Proxy功能,能够直接进行相关程序的编写. 但是,部分老项目使用PB6.5开发 研究后发现,其实PB6.5要操作Web Service也挺 ...

  3. < java.util >-- Iterator接口

    每一个集合都有自己的数据结构,都有特定的取出自己内部元素的方式.为了便于操作所有的容器,取出元素.将容器内部的取出方式按照一个统一的规则向外提供,这个规则就是Iterator接口. 也就说,只要通过该 ...

  4. UIView 添加子视图的常用方法

    1.  - (void)addSubview:(UIView *)view 这是最常用的方法有两个注意点 参数view可以是nil,运行不会报错,当然,父视图的subViews也不会增加. 此方法增加 ...

  5. 如何在Report Builder中使用fnd_profile.value

    在EBS的Report开发中,需要根据客户化的一个Profile来控制用户可以访问的数据,可是在开发的过程中发现一直取不到该Profile的值,后来百度才找到了原因. 解决方法: 1.添加用户参数p_ ...

  6. 20145120 《Java程序设计》实验四实验报告

    20145120 <Java程序设计>实验四实验报告 实验名称:Android开发基础 实验目的与要求: 用SDK成功编译出HelloWorld 实验内容.步骤 PSP 步骤 耗时 百分比 ...

  7. 【WildCard Matching】cpp

    题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...

  8. IntelliJ IDEA 15激活

    1.按正常的安装方法安装好IDEA : 2.使用iteblog提供的License server(服务器地址为http://www.iteblog.com/idea/key.php)进行注册 ---- ...

  9. 博文&零散信息阅读

    关于培养方案: 全国一线高校.网易云课堂和我院培养计划的区别主要体现在: 基础课上,我院删去了物理课程的必修要求. 专业课上,删去了汇编语言.编译原理.信息安全技术等学科的必修要求. 专业选修课上,我 ...

  10. UML工具选择

    今天在考虑UML工具的选择,个人要求比较简单:能够画用例图,时序图,活动图即可. 选择的工具主要有以下三个: 1.Enterprise Architect 2.Power Designer 15 3. ...