Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴个代妈,王记mod10了搞了一次WA,悲剧#include <iostream> using namespace std; int gs(int n, int p){ int sum = 0; while(n/p > 0){ n /= p; sum += n; } return sum; } int p1379(int s){ int zhengge = s/10; int prod = (zhengge%2 == 0) ? 1 : 9; int mod = s%10; if(mod >= 3 && mod <= 6) prod *= 3; if(mod == 9) prod *= 9; return prod%10; } int fac1379(int n){ int ans = 1; int pw2 = 1; while(pw2 <= n){ int pw5 = 1; while(pw2 * pw5 <= n){ int s = n / (pw2 * pw5); ans *= p1379(s); ans %= 10; pw5 *= 5; } pw2 *= 2; } return ans; } int ni(int n){ if(n == 1 || n == 9) return n; if(n == 3) return 7; if(n == 7) return 3; return -1; } int pp2[4] = {6, 2, 4, 8}; int main() { int n, m; cin >> n >> m; int p2 = gs(n, 2) - gs(m, 2) - gs(n-m, 2); int p5 = gs(n, 5) - gs(m, 5) - gs(n-m, 5); int ans = fac1379(n) * ni(fac1379(m)) * ni(fac1379(n-m)); ans %= 10; if(p2 > p5){ ans *= pp2[(p2-p5)%4]; ans %= 10; } if(p2 < p5){ ans = 5; } cout << ans << endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator