解题思路:
注意事项:
参考代码:
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 人评分
C语言训练-斐波纳契数列 (C语言代码)浏览:1174 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:620 |
本人酷爱递归实现很多问题,这里也是浏览:557 |
WU-格式化数据输出 (C语言代码)浏览:1755 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:648 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:577 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:1072 |
数组与指针的问题浏览:718 |
格式化数据输出 (C语言代码)浏览:822 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:580 |