看板 C_and_CPP 關於我們 聯絡資訊
這題我試過很多case都正確 但是還是吃WA QQ 下面是我的code 請強者們幫我看一下 感激不盡 #include<cstdio> #include<string> #include<cmath> using namespace std; # define P 46350 bool iscom[P]; unsigned int prime[5000]; int factor(unsigned int &test, unsigned int fac) { unsigned int count = 0; while(test % fac == 0) { test /= fac; count++; } return count; } int main() { unsigned int i, j, k, p, q, c, n, m, tmp; bool isprime, div; c = 0; for(i = 2; i <= P; i++) { if(!iscom[i]) { prime[c] = i; c++; for(j = 2*i; j <= P; j+=i) iscom[j] = true; } } while(scanf("%u %u", &n, &m) == 2) { tmp = m; if(m == 0 || (n == 0 && m != 1)) div = false; else if(n >= m || (n == 0 && m == 1)) div = true; else { isprime = true; for(i = 0; prime[i]*prime[i] <= m; i++) if(m % prime[i] == 0){ isprime = false; break; } if(isprime) div = false; else { div = true; for(i = 0; i < c; i++) { p = factor(m, prime[i]); if(p == 0) continue; q = 1; for(j = 2*prime[i]; j <= n; j+=prime[i]) { k = j; q += factor(k, prime[i]); if(q >= p) break; } if(q < p) { div = false; break; } if(m == 1) { div = true; break; } } } } if(div) printf("%u divides %u!\n", tmp, n); else printf("%u does not divide %u!\n", tmp, n); } return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.138.58.29