整数幂(多实例测试)
来源:互联网 发布:数据安全防护体系 编辑:程序博客网 时间:2024/05/16 07:15
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 1073 Solved: 610
Description
求A^B的最后三位数表示的整数(1<=A,B<=1000)
Input
n个测试实例,每个实例给出两个正整数A,B
Output
输出A^B的最后三位(没有前导0)
Sample Input
2
2 3
12 6
Sample Output
8 984
Code:
1 import java.util.Scanner;
2 import java.math.BigInteger;
3 public class Main{
4
5 public static void main(String[] args) {
6 Scanner input=new Scanner(System.in);
7 int n=input.nextInt();
8 while(n-->=0){
9 BigInteger A=input.nextBigInteger();
10 int B=input.nextInt();
11 A=A.pow(B); //将求得的大数A的B次幂赋值给A;
12 int len=A.toString().length(); //将大数A转换成String型求其长度.
13 if(len<=3)
14 System.out.println(A.intValue()); //若A长度小于3 则利用intValue()方法将A转化为int型.
15 else{
16 A=new BigInteger(A.toString().substring(len-3,len)); //截取大数A中后三位数字
17 System.out.println(A.intValue()); //利用intValue()方法将A转化为int型.
18 }
19 }
20 }
21 }
- 整数幂(多实例测试)
- 1090: 整数幂(多实例测试)
- zzuli OJ 1090: 整数幂(多实例测试)
- 郑轻OJ 1090: 整数幂(多实例测试)
- 轻院 1090 整数幂(多实例测试)
- 安全测试之整数溢出的一个实例
- 测试(整数、字符串比较;文件测试)
- 童年生活二三事(多实例测试)
- 1082: 敲7(多实例测试)
- 1095: 时间间隔(多实例测试)
- DBunit测试(实例)
- 从一个实例(整数幂指数)进行算法时间复杂度的分析
- Monkey实例测试(MarshalChen)
- 数模整数规划实例
- 大整数素性测试
- 多路径(multi-path)安装测试实例
- 题目 E: 敲7(多实例测试)
- zzuli OJ 1078: a+b(多实例测试1)
- hibernate抓取策略fetch=select /join/subselect
- 职场分享:什么情况下我们不能要求加薪
- codeforces Round #271(div2) C解题报告
- 操作系统 - 线程
- Notification framework层的处理流程分析
- 整数幂(多实例测试)
- 我的作品们
- 结构体含CString成员
- [安卓]Android Unable to resolve target 'android-8'
- ZOJ_3279 Ants 线段树+元素位置
- C语言中的函数
- 网络编程学习笔记(uname函数)
- [Leetcode]Triangle
- PE格式文件的代码注入