Advertisement
Ruhan_DIU

Template

Sep 28th, 2019
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.BigInteger;
  3. import java.util.*;
  4.  
  5. /* I S H M A M
  6. R U H A N
  7. */
  8.  
  9.  
  10. public class Main {
  11. //Fastest I/O Class Start
  12. static class FastReader{
  13. BufferedReader br;
  14. StringTokenizer st;
  15.  
  16. public FastReader(){
  17. br=new BufferedReader(new InputStreamReader(System.in));
  18. }
  19.  
  20. String next(){
  21. while(st==null || !st.hasMoreElements()){
  22. try{
  23. st=new StringTokenizer(br.readLine());
  24. }catch(Exception e){
  25.  
  26. }
  27. }
  28. return st.nextToken();
  29. }
  30.  
  31. int nextInt(){
  32. return Integer.parseInt(next());
  33. }
  34.  
  35. long nextLong(){
  36. return Long.parseLong(next());
  37. }
  38.  
  39. double nextDouble(){
  40. return Double.parseDouble(next());
  41. }
  42.  
  43. String nextLine(){
  44. String str="";
  45. try{
  46. str=br.readLine();
  47. }catch(Exception e){
  48.  
  49. }
  50. return str;
  51. }
  52.  
  53. }
  54. //Fastest I/O Class End
  55.  
  56. //Super Fast I/O class Start
  57. static class Reader
  58. {
  59. BufferedReader br;
  60. StringTokenizer st;
  61. final private int BUFFER_SIZE = 1 << 16;
  62. private DataInputStream din;
  63. private byte[] buffer;
  64. private int bufferPointer, bytesRead;
  65.  
  66. public Reader()
  67. {
  68. din = new DataInputStream(System.in);
  69. buffer = new byte[BUFFER_SIZE];
  70. bufferPointer = bytesRead = 0;
  71. }
  72.  
  73. String next(){
  74. while(st==null || !st.hasMoreElements()){
  75. try{
  76. st=new StringTokenizer(br.readLine());
  77. }catch(Exception e){
  78.  
  79. }
  80. }
  81. return st.nextToken();
  82. }
  83.  
  84. public Reader(String file_name) throws IOException
  85. {
  86. din = new DataInputStream(new FileInputStream(file_name));
  87. buffer = new byte[BUFFER_SIZE];
  88. bufferPointer = bytesRead = 0;
  89. }
  90.  
  91. public String readLine() throws IOException
  92. {
  93. byte[] buf = new byte[64]; // line length
  94. int cnt = 0, c;
  95. while ((c = read()) != -1)
  96. {
  97. if (c == '\n')
  98. break;
  99. buf[cnt++] = (byte) c;
  100. }
  101. return new String(buf, 0, cnt);
  102. }
  103.  
  104. public int nextInt() throws IOException
  105. {
  106. int ret = 0;
  107. byte c = read();
  108. while (c <= ' ')
  109. c = read();
  110. boolean neg = (c == '-');
  111. if (neg)
  112. c = read();
  113. do
  114. {
  115. ret = ret * 10 + c - '0';
  116. } while ((c = read()) >= '0' && c <= '9');
  117.  
  118. if (neg)
  119. return -ret;
  120. return ret;
  121. }
  122.  
  123. public long nextLong() throws IOException
  124. {
  125. long ret = 0;
  126. byte c = read();
  127. while (c <= ' ')
  128. c = read();
  129. boolean neg = (c == '-');
  130. if (neg)
  131. c = read();
  132. do {
  133. ret = ret * 10 + c - '0';
  134. }
  135. while ((c = read()) >= '0' && c <= '9');
  136. if (neg)
  137. return -ret;
  138. return ret;
  139. }
  140.  
  141. public double nextDouble() throws IOException
  142. {
  143. double ret = 0, div = 1;
  144. byte c = read();
  145. while (c <= ' ')
  146. c = read();
  147. boolean neg = (c == '-');
  148. if (neg)
  149. c = read();
  150.  
  151. do {
  152. ret = ret * 10 + c - '0';
  153. }
  154. while ((c = read()) >= '0' && c <= '9');
  155.  
  156. if (c == '.')
  157. {
  158. while ((c = read()) >= '0' && c <= '9')
  159. {
  160. ret += (c - '0') / (div *= 10);
  161. }
  162. }
  163.  
  164. if (neg)
  165. return -ret;
  166. return ret;
  167. }
  168.  
  169. private void fillBuffer() throws IOException
  170. {
  171. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  172. if (bytesRead == -1)
  173. buffer[0] = -1;
  174. }
  175.  
  176. private byte read() throws IOException
  177. {
  178. if (bufferPointer == bytesRead)
  179. fillBuffer();
  180. return buffer[bufferPointer++];
  181. }
  182.  
  183. public void close() throws IOException
  184. {
  185. if (din == null)
  186. return;
  187. din.close();
  188. }
  189. }
  190.  
  191. //Super Fast I/O Class End
  192.  
  193. static int maxN=10000007;
  194. static long[] dp=new long[maxN];
  195. static TreeMap<Integer, Integer> map=new TreeMap<>();
  196.  
  197. public static void main(String[] args) throws IOException {
  198. Main mn=new Main();
  199. // I/O System start
  200. Reader inf=new Reader();
  201. FastReader in=new FastReader();
  202. Scanner inp=new Scanner(System.in);
  203. PrintWriter out=new PrintWriter(System.out);
  204. // I/O System End
  205. long a=in.nextLong();
  206. long b=in.nextLong();
  207.  
  208. System.out.println(mn.pow(a, b));
  209.  
  210.  
  211. }
  212. static int k=0;
  213. public long getFibo(long n,long a,long b){
  214.  
  215. //System.out.println("Count : "+k++);
  216. //if(n<0) return 0;
  217. //if(n==1) return 1;
  218. if(n<=0) return 0;
  219.  
  220. //if(map.get((int)n)!= null) return map.get((int)n);
  221. if(dp[(int)n]!=-1)return dp[(int)n];
  222. //long value=getFibo(n-1)+getFibo(n-2);
  223. dp[(int)n]=Math.max(getFibo(n-1,a,b),getFibo(n-1,b,a));
  224. //map.put((int)n, (int)value);
  225. //dp[(int)n]=(int)value;
  226.  
  227. //return value;
  228. return dp[(int)n];
  229. }
  230.  
  231. //get power in O(sqrt-n) complexity
  232. public long pow(long a,long b){
  233. if(b==0)return 1;
  234. if(b%2==0)return pow(a*a,b/2);
  235. else{
  236. return a*pow(a,b-1);
  237. }
  238. }
  239.  
  240. //get gcd
  241. public long gcd(long a,long b)
  242. {
  243. if(a==0){
  244. return b;
  245. }else{
  246. return gcd(b%a,a);
  247. }
  248.  
  249. }
  250.  
  251. //get lcm
  252. public long lcm(long a,long b){
  253. return a*(b/gcd(a,b));
  254. }
  255.  
  256. //get sub sequence
  257. public static ArrayList<String> getAllSubSequence(String str)
  258. {
  259. if (str.length() == 0) {
  260. ArrayList<String> empty = new ArrayList<>();
  261. empty.add("");
  262. return empty;
  263. }
  264.  
  265. char ch = str.charAt(0);
  266.  
  267. String subStr = str.substring(1);
  268.  
  269. ArrayList<String> subSequences =getAllSubSequence(subStr);
  270.  
  271. ArrayList<String> res = new ArrayList<>();
  272. for (String val : subSequences) {
  273. res.add(val);
  274. res.add(ch + val);
  275. }
  276.  
  277. res.remove("");
  278.  
  279. return res;
  280. }
  281.  
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement