13131 - Divisors [Time Limit]

All about problems in Volume 130. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Post Reply
sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

13131 - Divisors [Time Limit]

Post by sith » Sat Jun 02, 2018 8:03 am

I must ask this question in the Volume 130 forum as Volume 131 is empty and by some reason I don't have permissions to start new topic there.

So, I managed to write the solution that should be correct but I got TE.

Code: Select all

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
    public static void main(String args[]) {

        Scanner scanner = new Scanner(System.in);

        int t = scanner.nextInt();

        for (int i = 0; i < t; i++) {
            int n = scanner.nextInt();
            int k = scanner.nextInt();

            Set<Integer> dividers = new HashSet<>();
            int sqrt = (int) Math.sqrt(n);
            for (int divider = 1; divider <= sqrt; divider++) {
                if (n % divider == 0) {
                    if (divider % k != 0) {
                        dividers.add(divider);
                    }

                    int otherDivider = n / divider;
                    if (otherDivider % k != 0) {
                        dividers.add(otherDivider);
                    }
                }
            }

            System.out.println(dividers.stream().mapToInt(number -> number).sum());
        }

    }
}
Could somebody give a hint about what I am missing for AC?

Post Reply

Return to “Volume 130 (13000-13099)”