Created
October 8, 2015 02:31
-
-
Save kunishi/b059dbbef60401c76369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @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