2019牛客假日团队赛3 - Times 17(大数)

链接:https://ac.nowcoder.com/acm/contest/945/J
来源:牛客网

题目描述

After realizing that there is much money to be made in software development, Farmer John has launched a small side business writing short programs for clients in the local farming industry.
Farmer John’s first programming task seems quite simple to him – almost too simple: his client wants him to write a program that takes a number N as input, and prints 17 times N as output. Farmer John has just finished writing this simple program when the client calls him up in a panic and informs him that the input and output both must be expressed as binary numbers, and that these might be quite large.
Please help Farmer John complete his programming task. Given an input number N, written in binary with at most 1000 digits, please write out the binary representation of 17 times N.

输入描述:

  • Line 1: The binary representation of N (at most 1000 digits).

输出描述:

  • Line 1: The binary representation of N times 17.

输入

10110111

输出

110000100111

OUTPUT DETAILS:
The binary number 10110111 is equal to 183 in decimal form.
183 x 17 = 3111 is 110000100111 in binary format.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String s = bufferedReader.readLine();
        BigInteger bigInteger = new BigInteger(s, 2);
        BigInteger ans = bigInteger.multiply(new BigInteger("17"));
        System.out.println(ans.toString(2));
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值