Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:

Each input file contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:

For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

Sample Input:

1234567899

Sample Output:

Yes
2469135798

不知道为什么有一个样例没过,觉得写得没毛病啊
 import java.math.BigInteger;
import java.util.Scanner; public class A { public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger a = cin.nextBigInteger();
BigInteger bb = a;
BigInteger c = BigInteger.valueOf(10);
BigInteger d;
BigInteger ans = a.add(bb);
BigInteger b = ans;
boolean book = true;
int[] book0 = new int[10];
while(!a.equals(BigInteger.valueOf(0))) {
// System.out.println(a.equals(0));
d = a.mod(c);
a = a.divide(c);
book0[d.intValue()] = 1;
}
while(!b.equals(BigInteger.ZERO)) {
d = b.mod(c);
b = b.divide(c);
if(book0[d.intValue()] != 1) {
book = false;
break;
}
}
if(book == false) {
System.out.println("No");
}
else {
System.out.println("Yes");
}
System.out.println(ans); } }

Java的大数计算BigNumber的更多相关文章

  1. Java & C++ 大数计算

    Java--大数计算,妈妈再也不用担心我的学习了 . BigInteger 英文API: http://docs.oracle.com/javase/8/docs/api/ 中文API: http:/ ...

  2. HDU 5686 斐波那契数列、Java求大数

    原题:http://acm.hdu.edu.cn/showproblem.php?pid=5686 当我们要求f[n]时,可以考虑为前n-1个1的情况有加了一个1. 此时有两种情况:当不适用第n个1进 ...

  3. 【Java】Float计算不准确

    大家可能都遇到过,float在计算某些值时,会有不准确的情况. 比如如下情况: > 计算不准确 package com.nicchagil.study.java.demo.No10float计算 ...

  4. Java BigInteger(大数,ACM比赛专用)

    用c或者C++处理大数比较麻烦,于是决心学习一下JAVA中大数运算. 先下载一个eclipse,具体的用法去问度娘吧 JAVA中有两个类BigInteger和BigDecimal分别表示大整数类和大浮 ...

  5. Java的大数操作分为BigInteger和BigDecimal

    Java的大数操作分为BigInteger和BigDecimal,但这两给类是分开使用的,有时候在编程的时候显得略微繁琐,现在编写了一个将二者合二为一的大数操作类. 大数操作类代码如下: 1 pack ...

  6. JAVA解决大数

    主题链接:CLICK HERE~ 有了Java求解大数变得如此简单,以后再也不用操心大数模板了.哦啦啦啦. import java.math.BigInteger; import java.math. ...

  7. 用Java进行大数处理(BigInteger)-hdu1042

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目描述: 代码实现: import java.util.Scanner; import jav ...

  8. Java闰年的计算,Calendar的用法

    Java闰年的计算,Calendar的用法 代码如下: package com.aaa.zuoye; import java.text.ParseException; import java.util ...

  9. Java基础-时间复杂度计算方式

    Java基础-时间复杂度计算方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   时间复杂度通常是衡量算法的优劣的,衡量算法的时间严格来讲是很难衡量的,由于不同的机器性能不用环境 ...

随机推荐

  1. 将Object对象转换成Map 属性名和值的形式

    将Java对象转换成Map的键值对形式 代码: package cn.lonelcoud.util; import com.sun.deploy.util.StringUtils; import ja ...

  2. iOS应用如何得知用户有新拍的图片?

    首先,应用要知道图片库中的新图片,最重要是要有图片库的访问权限.然后每张图片除了图片本身的构成要素(像素)外,还会保存图片的拍摄时间(时间戳),地点等相关信息.时间戳就是判断新拍照片的最主要依据.

  3. iOS实现从服务器请求json数据并转化成NSDictionary

    NSURL *url = [NSURL URLWithString:URL]; NSURLRequest *request = [NSURLRequest requestWithURL:url cac ...

  4. 在Angular中利用trackBy来提升性能

    在Angular的模板中遍历一个集合(collection)的时候你会这样写: <ul> <li *ngFor="let item of collection"& ...

  5. Java集合框架(一)—— Collection、Iterator和Foreach的用法

    1.Java集合概述 在编程中,常常需要集中存放多个数据.当然我们可以使用数组来保存多个对象.但数组长度不可变化,一旦在初始化时指定了数组长度,则这个数组长度是不可变的,如果需要保存个数变化的数据,数 ...

  6. Android使用百度地图出现闪退及定位时显示蓝屏问题

     目录 1.Android使用百度地图出现闪退 2.Android使用百度地图定位出现蓝屏问题     1.Android使用百度地图出现闪退 一般情况下出现闪退是在AndroidManifest.x ...

  7. JSP的内置对象以及作用域。

    最近在面试,一些基础的问题总是会被问到,虽然是基础,但是有些东西在工作中用的少,所以就有些记不清了,在面试的时候更因为紧张很容易造成原先知道的知识也会突然忘了的情况发生.所以在重新组织一下jsp的内置 ...

  8. Java并发编程-线程可见性&线程封闭&指令重排序

    一.指令重排序 例子如下: public class Visibility1 { public static boolean ready; public static int number; } pu ...

  9. yum仓库详细解读

    Yum:Yellowdog Updater,Modified的简称,起初由yellow dog发行版的开发者Terra Soft研发,用Python编写,后经杜克大学的Linux@Duke开发团队进行 ...

  10. Vmware下centos与windows能ping通并能上网

    1.桥接模式 2.NAT模式 3.Host-Only模式 1.桥接模式 vim /etc/udev/rules.d/70-persistent-net.rules 与/etc/sysconfig/ne ...