Java的大数计算BigNumber
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的更多相关文章
- Java & C++ 大数计算
Java--大数计算,妈妈再也不用担心我的学习了 . BigInteger 英文API: http://docs.oracle.com/javase/8/docs/api/ 中文API: http:/ ...
- HDU 5686 斐波那契数列、Java求大数
原题:http://acm.hdu.edu.cn/showproblem.php?pid=5686 当我们要求f[n]时,可以考虑为前n-1个1的情况有加了一个1. 此时有两种情况:当不适用第n个1进 ...
- 【Java】Float计算不准确
大家可能都遇到过,float在计算某些值时,会有不准确的情况. 比如如下情况: > 计算不准确 package com.nicchagil.study.java.demo.No10float计算 ...
- Java BigInteger(大数,ACM比赛专用)
用c或者C++处理大数比较麻烦,于是决心学习一下JAVA中大数运算. 先下载一个eclipse,具体的用法去问度娘吧 JAVA中有两个类BigInteger和BigDecimal分别表示大整数类和大浮 ...
- Java的大数操作分为BigInteger和BigDecimal
Java的大数操作分为BigInteger和BigDecimal,但这两给类是分开使用的,有时候在编程的时候显得略微繁琐,现在编写了一个将二者合二为一的大数操作类. 大数操作类代码如下: 1 pack ...
- JAVA解决大数
主题链接:CLICK HERE~ 有了Java求解大数变得如此简单,以后再也不用操心大数模板了.哦啦啦啦. import java.math.BigInteger; import java.math. ...
- 用Java进行大数处理(BigInteger)-hdu1042
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目描述: 代码实现: import java.util.Scanner; import jav ...
- Java闰年的计算,Calendar的用法
Java闰年的计算,Calendar的用法 代码如下: package com.aaa.zuoye; import java.text.ParseException; import java.util ...
- Java基础-时间复杂度计算方式
Java基础-时间复杂度计算方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 时间复杂度通常是衡量算法的优劣的,衡量算法的时间严格来讲是很难衡量的,由于不同的机器性能不用环境 ...
随机推荐
- idea 使用debugger技巧
1,背景 每个开发人员每天都离不开debugger,只要你在编码,就需要调试,作为一个开发快10年的老程序员每天都要写很多代码,当每个人接到任务的时候都会想,这些功能其实很快就能写完,没错,对于写代码 ...
- CentOS Crontab(定时任务)
安装crontab: yum install crontabs 说明: service crond start //启动服务 service crond stop //关闭服务 service cro ...
- XOR (莫队)
Time Limit: 2000 ms Memory Limit: 256 MB Description 给定一个含有n个整数的序列 a1, a2,..., an. 定义 f(x,x) = a[x ...
- Docker系列二:Docker的基本结构
Docker的基本结构 Docker 的三大基础组件 Docker有三个重要的概念:仓库 , 镜像 和 容器 ,它们是Docker的三大基出组件 Docker的组织结构 Docker处于操作系统和虚拟 ...
- java 集合框架(十六)Map
一.概述 Map是一个包含键值对的集合,一个map不能有重复的键(key),而且每个键至多只能对应一个值.Map同Collection一样,它的所有通用实现都会提供一个转换器构造函数,接收一个Map类 ...
- java 集合框架(十五)Deque
一.概述 Deque是Queue的子接口,我们知道Queue是一种队列形式,而Deque则是双向队列,它支持从两个端点方向检索和插入元素,因此Deque既可以支持LIFO形式也可以支持LIFO形式.D ...
- "No Python interpreter configured for the project " in Pycharm for python selenium
自动化测试问题: pyCharm提示python Interpreter没有设置,点击configure Python Interpreter,进入Settings 在 Project Interpr ...
- caffe+GAN︱PPGN生成模型5则官方案例(caffe版)
一.效果与架构 PPGN 整合了对抗训练.cnn特征匹配.降噪自编码.Langevin采样:在NIPS2016得到了Ian Goodfellow的介绍. PPGN生成的图像同类差异化大,可根据指定生成 ...
- 吐槽版︱MRO-Microsoft R Open快捷键+界面识别+功能设置
下载了之后,发现连运行(RUN键)在哪都不知道,蒙逼的在哪倒弄半天,都执行不了...问了别人,都说"ctrl+enter",但是我的电脑执行不了,于是今天就狠狠的一个一个按钮的点一 ...
- java Socket实现简单在线聊天(一)
最近的项目有一个在线网页交流的需求,由于很久以前做过的demo已经忘记的差不多了,因此便重新学习一下. 我计划的大致实现步骤分这样几大步: 1.使用awt组件和socket实现简单的单客户端向服务端持 ...