Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created October 8, 2015 02:31
Show Gist options
  • Save kunishi/b059dbbef60401c76369 to your computer and use it in GitHub Desktop.
Save kunishi/b059dbbef60401c76369 to your computer and use it in GitHub Desktop.
/* @JUDGE_ID: 26089N 113 C "" */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long double mod(long double a, long double b)
{
while (a >= b) {
a -= b;
}
printf("%L.0f %L.0f\n", a, b);
return a;
}
int main()
{
int n;
long double p, k, i;
while (scanf("%d", &n) == 1 && scanf("%Lf", &p) == 1) {
printf("n = %d p = %L.0f\n", n, p);
for (k = 2; k < p - 1; k ++) {
printf("k = %L.0f\n", k);
if (mod((p-1), (k-1)) == 0) {
i = powl(k, (long double)n);
if (i == p) {
printf("%L.0f\n", k);
break;
} else if (i > p) {
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment