猪猪爱喝纯牛奶


私信TA

用户名:liaolingqian

访问量:3695

签 名:

等  级
排  名 2645
经  验 2124
参赛次数 1
文章发表 19
年  龄 0
在职情况 学生
学  校 ytu
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

import java.math.BigInteger;

import java.util.Scanner;


public class llq1{

public static void main(String[] args) {

Scanner cin=new Scanner(System.in);

int n;

n=cin.nextInt();

System.out.println((int)(n*Math.log10(2)+1));//位数

String o="2";

BigInteger a=new BigInteger(o);

a=qsm(a,n);

a=a.subtract(BigInteger.ONE);

String s=a.toString();

if(s.length()<500) {

String t="";

int x=500-s.length();

for(int i=0;i<x;i++)

t=t+'0';

s=t+s;

}

int cnt=0;

String t="";

for(int i=s.length()-500;i<s.length();i++) {

t=t+s.charAt(i);

cnt++;

if(cnt==50)//每行输出50位共输出10行

{

cnt=0;

System.out.println(t);

t="";

}

}

}


private static BigInteger qsm(BigInteger x, int y) {//快速幂

BigInteger w=new BigInteger("10");

w=w.pow(500);

BigInteger ans=BigInteger.ONE;

while(y>0){

if(y%2==1)//为奇数

ans=ans.multiply(x).mod(w);

y>>=1;

x=x.multiply(x).mod(w);

}

return ans;

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区