Cod sursa(job #2142040)

Utilizator SlevySlevoaca Stefan-Gabriel Slevy Data 24 februarie 2018 18:11:55
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator java Status done
Runda Arhiva educationala Marime 0.97 kb
import java.io.*;
import java.util.Scanner;

class MyMath {
	
	static private final long MOD = 1999999973L;
	
	private MyMath() {}
	
	static long pow(long a, long b) {
		
		long res = 1L;
			
		for (long i = 0; (1L << i) <= b; i++) {
				
			if (((1L << i) & b) != 0) {
					
				res = (res * a) % MyMath.MOD;
			}
				
			a = (a * a) % MyMath.MOD;
		}
			
		return res % MyMath.MOD;
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		
		FileReader in = null;
		FileWriter out = null;
		
		try {
			
			in = new FileReader("lgput.in");
			out = new FileWriter("lgput.out");
			
			Scanner input = new Scanner(in);
			
			long x, y;
			
			x = input.nextLong();
			y = input.nextLong();
			
			String res = Long.toString(MyMath.pow(x, y));
			
			out.write(res);
			
			input.close();
			
		} finally {
			
			if (in != null)
				in.close();
			if (out != null)
				out.close();
		}
	}

}