您的位置:首页 > 其它

[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是否是素数,打表即可。

/*
━━━━━┒ギリギリ♂ 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: