Submission #582887


Source Code Expand

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
 
public class Main {
	public static void main(String[] args) throws NumberFormatException,
	IOException {Solve solve = new Solve();solve.solve();}
}
class Solve{
	void solve() throws NumberFormatException, IOException{
		ContestScanner in = new ContestScanner();
		Writer out = new Writer();
		String[] line = in.readLine().split("/");
		long x = Long.parseLong(line[0]);
		long y = Long.parseLong(line[1]);
		long g = gcd(x, y);
		x /= g;
		y /= g;
		long k = (2*x-y)/y/y;
		long n = y;
		long oldX = x;
		if(k>1){
			x *= k;
			n *= k;
		}
		int count = 0;
		while(true){
			long m = n*(n+1)/2-x;
			if(0 < m){
				if(m > n) break;
				System.out.println(n+" "+m);
				count++;
			}
			x += oldX;
			n += y;
		}
		if(count==0) System.out.println("Impossible");
	}
	
	static long gcd(long a, long b){
		return b == 0 ? a : gcd(b, a % b);
	}
}
 
class MultiSet<T> extends HashMap<T, Integer>{
	@Override
	public Integer get(Object key){return containsKey(key)?super.get(key):0;}
	public void add(T key,int v){put(key,get(key)+v);}
	public void add(T key){put(key,get(key)+1);}
}
class Timer{
	long time;
	public void set(){time = System.currentTimeMillis();}
	public long stop(){return System.currentTimeMillis()-time;}
}
class Writer extends PrintWriter{
	public Writer(String filename) throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer() throws IOException{super(System.out);}
}
class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;
	public ContestScanner() throws FileNotFoundException 
	{reader = new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename) throws FileNotFoundException
	{reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}
	public String readLine() throws IOException{return reader.readLine();}
	public long nextLong() throws IOException, NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt() throws NumberFormatException, IOException
	{return (int) nextLong();}
	public double nextDouble() throws NumberFormatException, IOException 
	{return Double.parseDouble(nextToken());}
}

Submission Info

Submission Time
Task C - 平均値太郎の憂鬱 ( The melancholy of Taro Heikinchi )
User threepipes_s
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 2774 Byte
Status AC
Exec Time 327 ms
Memory 21028 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 60
Set Name Test Cases
All 00_killer.txt, 00_max.txt, 00_min.txt, 00_min2.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rnd2_00.txt, 02_rnd2_01.txt, 02_rnd2_02.txt, 02_rnd2_03.txt, 02_rnd2_04.txt, 02_rnd2_05.txt, 02_rnd2_06.txt, 02_rnd2_07.txt, 02_rnd2_08.txt, 02_rnd2_09.txt, 02_rnd2_10.txt, 02_rnd2_11.txt, 02_rnd2_12.txt, 02_rnd2_13.txt, 02_rnd2_14.txt, 02_rnd2_15.txt, 02_rnd2_16.txt, 02_rnd2_17.txt, 02_rnd2_18.txt, 02_rnd2_19.txt, 03_smallrnd_00.txt, 03_smallrnd_01.txt, 03_smallrnd_02.txt, 03_smallrnd_03.txt, 03_smallrnd_04.txt, 03_smallrnd_05.txt, 03_smallrnd_06.txt, 03_smallrnd_07.txt, 03_smallrnd_08.txt, 03_smallrnd_09.txt, 04_primes_01.txt, 04_primes_02.txt
Case Name Status Exec Time Memory
00_killer.txt AC 322 ms 21000 KB
00_max.txt AC 321 ms 20932 KB
00_min.txt AC 311 ms 20900 KB
00_min2.txt AC 313 ms 21000 KB
00_sample_01.txt AC 310 ms 20940 KB
00_sample_02.txt AC 307 ms 20988 KB
00_sample_03.txt AC 316 ms 20916 KB
00_sample_04.txt AC 313 ms 20932 KB
01_rnd_00.txt AC 312 ms 20880 KB
01_rnd_01.txt AC 312 ms 20964 KB
01_rnd_02.txt AC 310 ms 20984 KB
01_rnd_03.txt AC 319 ms 20888 KB
01_rnd_04.txt AC 316 ms 20948 KB
01_rnd_05.txt AC 312 ms 20904 KB
01_rnd_06.txt AC 309 ms 20900 KB
01_rnd_07.txt AC 313 ms 20948 KB
01_rnd_08.txt AC 323 ms 20928 KB
01_rnd_09.txt AC 322 ms 20972 KB
01_rnd_10.txt AC 310 ms 20940 KB
01_rnd_11.txt AC 327 ms 20940 KB
01_rnd_12.txt AC 314 ms 20936 KB
01_rnd_13.txt AC 327 ms 20964 KB
01_rnd_14.txt AC 316 ms 20984 KB
01_rnd_15.txt AC 323 ms 20900 KB
01_rnd_16.txt AC 314 ms 20888 KB
01_rnd_17.txt AC 308 ms 21000 KB
01_rnd_18.txt AC 319 ms 20952 KB
01_rnd_19.txt AC 306 ms 20996 KB
02_rnd2_00.txt AC 310 ms 21000 KB
02_rnd2_01.txt AC 305 ms 20980 KB
02_rnd2_02.txt AC 306 ms 20928 KB
02_rnd2_03.txt AC 312 ms 20936 KB
02_rnd2_04.txt AC 306 ms 20884 KB
02_rnd2_05.txt AC 310 ms 20920 KB
02_rnd2_06.txt AC 312 ms 20980 KB
02_rnd2_07.txt AC 309 ms 20980 KB
02_rnd2_08.txt AC 304 ms 20960 KB
02_rnd2_09.txt AC 298 ms 20904 KB
02_rnd2_10.txt AC 293 ms 20940 KB
02_rnd2_11.txt AC 312 ms 20888 KB
02_rnd2_12.txt AC 300 ms 20968 KB
02_rnd2_13.txt AC 299 ms 20996 KB
02_rnd2_14.txt AC 300 ms 20884 KB
02_rnd2_15.txt AC 298 ms 21028 KB
02_rnd2_16.txt AC 299 ms 20892 KB
02_rnd2_17.txt AC 295 ms 20924 KB
02_rnd2_18.txt AC 304 ms 20928 KB
02_rnd2_19.txt AC 301 ms 20988 KB
03_smallrnd_00.txt AC 294 ms 20988 KB
03_smallrnd_01.txt AC 295 ms 20932 KB
03_smallrnd_02.txt AC 295 ms 21008 KB
03_smallrnd_03.txt AC 308 ms 20924 KB
03_smallrnd_04.txt AC 305 ms 20924 KB
03_smallrnd_05.txt AC 299 ms 20996 KB
03_smallrnd_06.txt AC 299 ms 20952 KB
03_smallrnd_07.txt AC 298 ms 20980 KB
03_smallrnd_08.txt AC 299 ms 20972 KB
03_smallrnd_09.txt AC 300 ms 20920 KB
04_primes_01.txt AC 301 ms 20940 KB
04_primes_02.txt AC 307 ms 20980 KB