Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.StringTokenizer;
- public class C {
- BufferedReader in;
- PrintWriter out;
- StringTokenizer tok = new StringTokenizer("");
- public static void main(String[] args) {
- new C().run();
- }
- public void run() {
- try {
- long t1 = System.currentTimeMillis();
- init();
- solve();
- out.close();
- long t2 = System.currentTimeMillis();
- System.err.println(t2 - t1);
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
- }
- }
- void init() throws IOException {
- try {
- in = new BufferedReader(new FileReader("input.txt"));
- out = new PrintWriter("output.txt");
- } catch (Exception e) {
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(System.out);
- }
- }
- String readString() throws IOException {
- while (!tok.hasMoreTokens()) {
- try {
- tok = new StringTokenizer(in.readLine());
- } catch (Exception e) {
- return null;
- }
- }
- return tok.nextToken();
- }
- int readInt() throws IOException {
- return Integer.parseInt(readString());
- }
- long readLong() throws IOException {
- return Long.parseLong(readString());
- }
- void solve() throws IOException {
- int k = readInt();
- List<Integer> divisors = new ArrayList<Integer>();
- for (int d = 1; d * d <= k; ++d) {
- if (k % d == 0) {
- divisors.add(d);
- if (d * d != k) {
- divisors.add(k / d);
- }
- }
- }
- class Pair {
- long a, b;
- public Pair(long a, long b) {
- this.a = a;
- this.b = b;
- }
- }
- List<Pair> answers = new ArrayList<Pair>();
- int size = divisors.size();
- for (int a: divisors) {
- for (int i = 0; i < size; ++i) {
- int b = divisors.get(i);
- int gcd = gcd(a, b);
- if (gcd == 1) {
- long sum = a + b;
- sum *= k;
- long mult = 1L * a * b;
- if (sum % mult != 0) continue;
- long g = sum / mult;
- answers.add(new Pair(g * a, g * b));
- }
- }
- }
- out.println(answers.size());
- for (Pair answer: answers) {
- out.println(answer.a + " " + answer.b);
- }
- }
- int gcd(int a, int b) {
- return (a == 0? b: gcd(b % a, a));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement