#!/usr/bin/perl
use 5.016;
use warnings;
sub gcd { $_[1] ? gcd($_[1], $_[0] % $_[1]) : $_[0] }
sub lcm { $_[0] * $_[1] / gcd($_[0], $_[1]) }
sub f {
my ($p, $q, $e) = @_;
my $lcm = lcm($p - 1, $q - 1);
grep{ !($_ % $e) && ($_ != $e) } map{ $_ * $lcm + 1 } (1 .. $p * $q);
}
say
join ' ', f
(map{ <STDIN> }(1 .. 3));
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwoKc3ViIGdjZCB7ICRfWzFdID8gZ2NkKCRfWzFdLCAkX1swXSAlICRfWzFdKSA6ICRfWzBdIH0Kc3ViIGxjbSB7ICRfWzBdICogJF9bMV0gLyBnY2QoJF9bMF0sICRfWzFdKSB9CgpzdWIgZiB7CglteSAoJHAsICRxLCAkZSkgPSBAXzsKCglteSAkbGNtID0gbGNtKCRwIC0gMSwgJHEgLSAxKTsKCglteSBAcmNhID0gbWFweyAkXyAvICRlIH0KCQlncmVweyAhKCRfICUgJGUpICYmICgkXyAhPSAkZSkgfQoJCW1hcHsgJF8gKiAkbGNtICsgMSB9ICgxIC4uICRwICogJHEpOwoKCXJldHVybiAkcmNhWzBdOwp9CgpzYXkgam9pbiAnICcsIGYobWFweyA8U1RESU4+IH0oMSAuLiAzKSk7