# ACM-ICPC 寒假练习 06

## UVaOJ 575

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  #include using namespace std; int Pow(int x, int y); int main() { string x; while(cin >> x) { if(x == "0") { break; } int ans = 0; for(int i = 0; i < x.length(); i++) { ans += (x[i] - '0') * (Pow(2, x.length() - i) - 1); } cout << ans << endl; } return 0; } int Pow(int x, int y) { int ret = 1; for(int i = 1; i <= y; i++) { ret *= x; } return ret; } 

## UVaOJ 10110

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  #include #include using namespace std; int main() { long long N; while(cin >> N) { if(N == 0) { break; } long long x = (long long)floor(sqrt(N * 1.0) + 0.5); if(x * x == N) { cout << "yes" << endl; } else { cout << "no" << endl; } } return 0; } 

## UVaOJ 550

$N$ 的最后一位数字为 $D$，那么 $S$ 的最后一位数字记为 $T = D \cdot M \mod B$（这里为 $B$ 进制）。

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  #include using namespace std; int main() { int B, D, M; while(cin >> B >> D >> M) { int nCnt = 1; int nD = D; while((nD = M * (nD % B) + (nD / B)) && nD != D) { nCnt++; } cout << nCnt << endl; } return 0; } 

## UVaOJ 568

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  #include #include using namespace std; const int MAX = 100000; int main() { int N; while(cin >> N) { int ans = 1; for(int i = 1; i <= N; i++) { ans *= i; while(ans % 10 == 0) { ans /= 10; } ans %= MAX; } cout << setw(5) << N << " -> " << ans % 10 << endl; } } 

## UVaOJ 408

\begin{align*}\mathrm{seed}(x + 1) &= [\mathrm{seed}(x) + \mathrm{STEP}] \mod \mathrm{MOD} \\ &= [\mathrm{seed}(x - 1) + 2 \cdot \mathrm{STEP}] \mod \mathrm{MOD} \\ &= [\mathrm{seed}(x - 2) + 3 \cdot \mathrm{STEP}] \mod \mathrm{MOD} \\ &= \cdots \\ &= [\mathrm{seed}(0) + (x + 1) \cdot \mathrm{STEP}] \mod \mathrm{MOD}\end{align*}

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  #include #include using namespace std; int gcd(int x, int y); int main() { int x, y; while(cin >> x >> y) { if(gcd(x, y) == 1) { cout << setw(10) << x << setw(10) << y << " Good Choice" << endl; } else { cout << setw(10) << x << setw(10) << y << " Bad Choice" << endl; } cout << endl; } return 0; } int gcd(int x, int y) { if(y == 0) { return x; } else { return gcd(y, x % y); } } 

## UVaOJ 350

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  #include #include using namespace std; const int MAX = 10240; int f[MAX]; int main() { int nCase = 0; int Z, I, M, L; while(cin >> Z >> I >> M >> L) { if(Z == 0 && I == 0 && M == 0 && L == 0) { break; } int nCnt = -1; memset(f, 0, sizeof(f)); do { L = ((Z % M) * (L % M) + (I % M)) % M; f[L]++; nCnt++; } while(f[L] == 1); cout << "Case " << ++nCase << ": " << nCnt << endl; } return 0; } 

## UVaOJ 10061

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  #include #include using namespace std; const int MAX = 1 << 20; double pLog[MAX]; int main() { for(int i = 1; i < MAX; i++) { pLog[i] = pLog[i - 1] + log(i); } int N, B; while(cin >> N >> B) { int nLen = (int)floor(pLog[N] / log(B) + 1E-9) + 1; int nMaxFactor, nFactorCnt = 0, nCnt = 0; for(int i = 2; i <= B; i++) { nFactorCnt = 0; while(B % i == 0) { nMaxFactor = i; nFactorCnt++; B /= i; } } while(N) { N /= nMaxFactor; nCnt += N; } cout << nCnt / nFactorCnt << " " << nLen << endl; } return 0; } 

## UVaOJ 10392

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41  #include #include #include using namespace std; const int MAX = 1000020; vector pVec; bool pVisited[MAX]; int main() { memset(pVisited, false, sizeof(pVisited)); for(int i = 2; i < MAX; i++) { if(!pVisited[i]) { pVec.push_back(i); } for(int j = i + i; j < MAX; j += i) { pVisited[j] = true; } } long long N; while(cin >> N) { if(N < 0) { break; } int nCnt = 0; for(int i = 0; i < pVec.size(); i++) { if(N < pVec[i]) { break; } while(N % pVec[i] == 0) { cout << " " << pVec[i] << endl; N /= pVec[i]; nCnt++; } } if(nCnt == 0 || N != 1) { cout << " " << N << endl; } cout << endl; } return 0; } 

## UVaOJ 10879

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  #include using namespace std; int main() { int T, N; cin >> T; for(int i = 1; i <= T; i++) { cin >> N; cout << "Case #" << i << ": " << N; int nCnt = 0; for(int j = 2; j * j <= N; j++) { if(N % j == 0) { cout << " = " << j << " * " << N / j; nCnt++; } if(nCnt == 2) { break; } } cout << endl; } return 0; }