Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Solve using your language of choice

Name: Anonymous 2011-04-13 9:05

http://i56.tinypic.com/9qlh52.png

my solution in Java

import java.io.*;
import java.util.*;

public class ProblemF {
   
    public static void main(String[] args) throws Exception {
        BufferedReader fileIn = new BufferedReader(new FileReader("f.in"));
       
        String line = null;
        while ((line = fileIn.readLine()) != null) {
            int number = Integer.parseInt(line);
            if (number <= 0 || number >= 100000000) {
                break;
            }
            System.out.println(number +" : "+ getOrderedPairs(number));
        }
    }
   
    public static String getOrderedPairs(int number) {
        StringBuffer buff = new StringBuffer();
       
        int pairCount = 0;
        for (int i = 1; i <= number; i++) {
            for (int j = i; j <= number; j++) {
                int sum = getSummation(i, j);
                if (sum == number) {
                    pairCount++;
                    buff.append(" ("+ i +","+ j +")");
                    break;
                } else if (sum > number) {
                    break;
                }
            }
        }
       
        buff.insert(0, pairCount +" :");
       
        return buff.toString();
    }
   
    public static int getSummation(int tempA, int tempB) {
        int a = tempA - 1;
        int b = tempB;
        int sumB = ((b * (b + 1)) / 2);
        int sumA = ((a * (a + 1)) / 2);
        return sumB - sumA;
    }
   
}

Name: Anonymous 2011-04-14 18:03

>>28

; in: n = edx, edi = ptr to pairs
; out: edi = # of pairs
    xor eax, eax ; a
    xor ebx, ebx ; b
    xor ecx, ecx ; x
    mov esi, edi
    jmp inloop
nextloop:
    cmp ecx, edx
    jnz notfound
    stosd
    xchg eax, ebx
    stosd
    xchg eax, ebx
notfound:
    cmp ecx, edx
    jb xlessn
    sub ecx, eax
    inc eax
    jmp inloop
xlessn:
    inc ebx
    add ecx, ebx
inloop:
    cmp ebx, edx
    jbe nextloop
    sub edi, esi
    shr edi, 4
    ret

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List