uva 1434 - YAPTCHA(数论)
2014-07-05 22:14
351 查看
题目链接:uva 1434 - YAPTCHA
题目大意:给定n和k,求题目中给定的式子S(n)。
解题思路:威尔逊定理,x为素数时有,((x−1)!+1)%x==0,所以对于本题,如果3*k+7为素数的话,[(3k+6)!+1(3k+7−[(3k+6)!3k+7]]=1
题目大意:给定n和k,求题目中给定的式子S(n)。
解题思路:威尔逊定理,x为素数时有,((x−1)!+1)%x==0,所以对于本题,如果3*k+7为素数的话,[(3k+6)!+1(3k+7−[(3k+6)!3k+7]]=1
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int maxn = 1e6; int ans[maxn+5], vis[maxn*4+5]; void primeTable (int n) { memset(vis, 0, sizeof(vis)); for (int i = 2; i <= n; i++) { if (vis[i]) continue; for (int j = 2 * i; j <= n; j += i) vis[j] = 1; } } int main () { primeTable(maxn*4); ans[1] = 0; for (int i = 2; i <= maxn; i++) ans[i] = ans[i-1] + (vis[3*i+7] ? 0 : 1); int cas, n; scanf("%d", &cas); while (cas--) { scanf("%d", &n); printf("%d\n", ans ); } return 0; }
相关文章推荐
- uva 1434 - YAPTCHA(数论)
- UVA 1434 - YAPTCHA(数论)
- [UVA1434] YAPTCHA(数论,威尔逊定理)
- UVA 1434 - YAPTCHA(数论)
- HDU 2973 / UVa 1434 / CERC 2008 YAPTCHA (威尔逊定理及其逆定理)
- UVA 1434 YAPTCHA(威尔逊定理简单应用)
- UVA - 1434 YAPTCHA (威尔逊定理)
- UVA 10976 分数拆分(数论+枚举)
- IIUC ONLINE CONTEST 2008 / UVa 11388 GCD LCM (数论)
- UVA 550 (暑假-数论 -B - Multiplying by Rotation)
- uva11428(数论+二分)
- UVa 11121 Base -2 (数论 & -2进制 & 补足思想)
- UVA 11246 - K-Multiple Free set (数论/容斥)
- UVa 11806 Cheerleaders (数论容斥原理)
- uva 12119 - The Bells are Ringing(数论+枚举)
- UVA11388 GCD LCM(数论)
- uva 10892 - LCM Cardinality(数论)
- uva 1315 - Crazy tea party(数论)
- UVA 11609 - Teams(数论+推理+快速幂)
- UVA10090 数论基础 exgcd