这道题的巧妙方法没有想出来,但是算是优化的暴力破解吧。Accepted

import java.io.BufferedInputStream;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner scan = new Scanner(new BufferedInputStream(System.in));
while(scan.hasNextInt()){
int n = scan.nextInt();
int m = scan.nextInt();
if(n==0&&m==0){
break;
}
int right3OfN = n%1000;
int result = right3OfN;
while(--m!=0){
result = result*right3OfN%1000;
}
System.out.println(result);
}
scan.close();
}
}

但是,发现了个问题

如果我把1-999的m次方可能的结果用静态容器保存起来时,结果就 Wrong Answer

没想通,有谁知道么?

以下是JAVA实现:

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner scan = new Scanner(new BufferedInputStream(System.in));
while(scan.hasNextInt()){
int n = scan.nextInt();
int m = scan.nextInt();
if(n==0&&m==0){
break;
}
int right3OfN = n%1000;
ArrayList<Integer> right3s = arrays.get(right3OfN);
System.out.println(right3s.get((m-1)%right3s.size()));
}
scan.close();
} static ArrayList<ArrayList<Integer>> arrays = getRightMost3DigitArray(); static ArrayList<ArrayList<Integer>> getRightMost3DigitArray(){
ArrayList<ArrayList<Integer>> arrays = new ArrayList<>();
for(int i = 0 ; i != 1000 ; i ++){
ArrayList<Integer> integers = new ArrayList<>();
int right3OfI = i;
integers.add(right3OfI);
int right3 = right3OfI;
while(true){
right3 = right3 * right3OfI%1000;
if(integers.contains(right3)){
break;
}else{
integers.add(right3);
}
}
arrays.add(integers);
}
return arrays;
}
}

HDOJ-ACM2035(JAVA) 人见人爱A^B的更多相关文章

  1. hdoj 1753 (Java)

    刚刚开始用Java,代码难免不够简洁. import java.math.BigDecimal; import java.util.Scanner; public class Main { publi ...

  2. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  3. hdoj 2035 人见人爱A^B

    人见人爱A^B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  4. hdoj上的一题和程序设计第二次作业的拓展-人见人爱a+b

    hdoj上一道有意思的题目,题目: 人见人爱a+b 敲的也蛮快的,大概十分钟左右就AC了.代码如下: 人见人爱a+b #include<stdio.h> int main() { int ...

  5. HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

    Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现 ...

  6. HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)

    Problem Description As the increase of population, the living space for people is becoming smaller a ...

  7. HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)

    Problem Description Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me wha ...

  8. hdoj 1753 大明A+B 高精度/java

    大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. hdoj 1002 A + B Problem II 高精度 java

    A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. CODEVS 3943 数学奇才琪露诺

    [题目描述 Description] 作为上白泽慧音老师的出色弟子,数学奇才琪露诺在算术方面有很深的造诣.今天,codevs有幸请到了这位数学界的奇葩作为本场考试的第一题主考官. 琪露诺喜欢0-9之间 ...

  2. Vm image download resource

    http://vmdepot.msopentech.com/List/Index http://www.hanselman.com/blog/Over400VirtualMachineImagesOf ...

  3. ExtJS4加载FormPanel数据的几种方式

    我们做web应用最多的就是处理表单,extjs为我们提供了很多处理表单的功能,很多初学者疑惑怎么加载表单数据,到底能用什么方式加载?本文中,我将我自己实验过的进行一下总结,自己备忘,也希望能帮助到其他 ...

  4. [JavaScript] js判断是否在微信浏览器中打开

    用JS来判断了,经过查找资料终于实现了效果, function is_weixn(){     var ua = navigator.userAgent.toLowerCase();     if(u ...

  5. CELERY里,这个WARNING如何消除?

    原来命令行里有提示,保证用-n给与不同的名字即可. 比如: [program:celeryd]command=/usr/local/python27/bin/celery worker --app=s ...

  6. JAVA 字符串编码总结

    java 为了解决跨平台,字符串编码的有点特殊 String newStr = new String(oldStr.getBytes(), "UTF-8");java中的Strin ...

  7. easyui源码翻译1.32--EasyLoader(简单加载)

    前言 扩展自$.fn.datebox.defaults,使用$.fn.datetimebox.defaults重写默认值对象.下载该插件翻译源码 源码 /** * jQuery EasyUI 1.3. ...

  8. AHB总线和APB总线

    AHB主要用于高性能模块(如CPU.DMA和DSP等)之间的连接,作为SoC的片上系统总线,它包括以下一些特性:单个时钟边沿操作:非三态的实现方式:支持突发传输:支持分段传输:支持多个主控制器:可配置 ...

  9. Android WebView 开发详解(二)

    转载请注明出处  http://blog.csdn.net/typename/article/details/39495409 powered by miechal zhao   概览: Androi ...

  10. Layout Resource官方教程(1)简介

    Layout Resource SEE ALSO Layouts A layout resource defines the architecture for the UI in an Activit ...