1 // accepted 420 K 16 Ms 2 // consider 0 and n! Does not divide 3 // 1 and 0! Divides 4 # include <cstdio> 5 # include <cstring> 6 # include <iostream> 7 using namespace STD; 8 const int imax_n = (1 <16) + 5; 9 int pri [imax_n]; 10 int CNT; 11 void prime () 12 {13 for (INT I = 2; I <imax_n; I ++) 14 {15 if (long) I * I <(long) imax_n) 16 for (Int J = I * I; j <imax_n; j + = I) 17 {18 pri [J] = 1; 19} 20} 21 CNT = 0; 22 for (INT I = 2; I <imax_n; I ++) 23 if (PRI [I] = 0) 24 pri [CNT ++] = I; 25} 26 int getnumber (int N, int K) 27 {28 int ans = 0; 29 If (k = 0) Return-1; 30 While (n> 0) 31 {32 ans + = N/K; 33 N/= K; 34} 35 return ans; 36} 37 int split (int n, int m) 38 {39 int T; 40 // printf ("n = % d \ n", n); 41 if (n = 0) return 0; 42 if (M = 0) 43 {44 If (n = 1) return 1; 45 return 0; 46} 47 for (INT I = 0; I <CNT & (_ int64) PRI [I] * Pri [I] <= (_ int64) N; I ++) 48 {49 If (N % pri [I] = 0) 50 {51 // printf ("pri = % d \ n", PRI [I]); 52 T = 0; 53 While (N % pri [I] = 0) 54 {55 t ++; 56 N/= pri [I]; 57} 58 int temp = getnumber (M, PRI [I]); 59 // printf ("temp = % d t = % d \ n", temp, T); 60 if (temp <t) return 0; 61} 62} 63 If (n! = 1) 64 {65 int temp = getnumber (m, n); 66 If (temp <1) return 0; 67} 68 return 1; 69} 70 int main () 71 {72 prime (); 73 int n, m; 74 while (scanf ("% d", & N, & M )! = EOF) 75 {76 int ans = Split (m, n); 77 If (ANS = 1) 78 {79 printf ("% d divides % d! \ N ", m, n); 80} 81 else82 {83 printf (" % d does not divide % d! \ N ", m, n); 84} 85} 86 return 0; 87}
View code
Poj2649 Number Theory