[UVA1434] YAPTCHA(数论,威尔逊定理)
2016-08-30 23:19
375 查看
题目链接:http://acm.hust.edu.cn/vjudge/problem/36250
题意:求那个式子。
设3k+7=x,则化简成 Sn=Σ(k=1~n) (((x-1)!+1/x)-[(x-1)!/x])
根据威尔逊定理,假如一个数p是素数,则这个数满足:(p-1)!=-1 (mod p)即 (p-1)!-1=0(mod p)。
由于被减数满足此条件,而减数表示向下取整。则被减数整除,减数一定是向下取整的。所以结果减数比被减数要小1,否则减数和被减数相等,即为0。问题转换成了求3k+7是否是素数,打表即可。
题意:求那个式子。
设3k+7=x,则化简成 Sn=Σ(k=1~n) (((x-1)!+1/x)-[(x-1)!/x])
根据威尔逊定理,假如一个数p是素数,则这个数满足:(p-1)!=-1 (mod p)即 (p-1)!-1=0(mod p)。
由于被减数满足此条件,而减数表示向下取整。则被减数整除,减数一定是向下取整的。所以结果减数比被减数要小1,否则减数和被减数相等,即为0。问题转换成了求3k+7是否是素数,打表即可。
/* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┃┃┃┃┃┃ ┻┻┻┻┻┻ */ #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; #define fr first #define sc second #define cl clear #define BUG puts("here!!!") #define W(a) while(a--) #define pb(a) push_back(a) #define Rint(a) scanf("%d", &(a)) #define Rll(a) scanf("%lld", &a) #define Rs(a) scanf("%s", a) #define Cin(a) cin >> a #define FRead() freopen("in", "r", stdin) #define FWrite() freopen("out", "w", stdout) #define Rep(i, len) for(int i = 0; i < (len); i++) #define For(i, a, len) for(int i = (a); i < (len); i++) #define Cls(a) memset((a), 0, sizeof(a)) #define Clr(a, x) memset((a), (x), sizeof(a)) #define Full(a) memset((a), 0x7f, sizeof(a)) #define lrt rt << 1 #define rrt rt << 1 | 1 #define pi 3.14159265359 #define RT return #define lowbit(x) x & (-x) #define onenum(x) __builtin_popcount(x) typedef long long LL; typedef long double LD; typedef unsigned long long Uint; typedef pair<int, int> pii; typedef pair<LL, LL> pLL; typedef pair<string, LL> psi; typedef map<string, LL> msi; typedef vector<LL> vi; typedef vector<LL> vl; typedef vector<vl> vvl; typedef vector<bool> vb; const int maxn = 6000100; bool isprime[maxn]; int n; int dp[maxn/6]; void init() { int nn = int(sqrt(maxn)); memset(isprime, true, sizeof(isprime)); isprime[0] = isprime[1] = 0; for(int i = 2; i <= nn; i++) { if(isprime[i]) { int p = maxn / i; for(int j = 2; j <= p; j++) { isprime[j*i] = 0; } } } } int main() { // FRead(); init(); Cls(dp); dp[1] = 0; For(i, 2, 1000010) { dp[i] = dp[i-1]; if(isprime[3*i+7]) dp[i]++; } int T; Rint(T); W(T) { Rint(n); cout << dp << endl; } RT 0; }
相关文章推荐
- UVA 1434 - YAPTCHA(数论)
- UVA - 1434 YAPTCHA (威尔逊定理)
- uva 1434 - YAPTCHA(数论)
- uva 1434 - YAPTCHA(数论)
- HDU 2973 / UVa 1434 / CERC 2008 YAPTCHA (威尔逊定理及其逆定理)
- UVA 1434 YAPTCHA(威尔逊定理简单应用)
- UVA 1434 - YAPTCHA(数论)
- (hdu 2973 YAPTCHA) <数论—威尔逊定理>
- Hdu 2973 YAPTCHA (数论 威尔逊定理)
- ACM 数论 HDU 2973 YAPTCHA 威尔逊定理
- uva1434威尔逊定理
- 20141002 【 数论——组合数 】 UVa 10375 Choose and divide
- Uva 10006 Carmichael Numbers(数论、快速幂、素数筛法)
- 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?
- UVa 568 Just the Facts (数论&打表&不打表)
- (数论2.1.3)UVA 10533 Digit Primes(埃拉托斯特尼筛法)
- UVA 1319 - Maximum(数论+贪心)
- Choose and divide UVA - 10375 (数论+唯一分解定理)
- 数论专题(一) Uva 10780+Uva 10892+Uva 11076
- [UVA10139]Factovisors(数论,质因数)