HDU - 2973:YAPTCHA (威尔逊定理)】的更多相关文章

传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! + 1 = p*q. 令 f(K) =  ①如果 3K+7 为素数,则 (3K+7-1)! ≡ -1(mod 3K+7),即 (3K+6)! = (3K+7)*q -1. 那么表达式 可化简为 [ (3K+7)*q / (3K+7) - 1 / (3K+7) ] = [ q - 1 / (3K+7…
YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1885    Accepted Submission(s): 971   Problem Description The math department has been having problems lately. Due to immense amount of u…
先上题目: YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 463    Accepted Submission(s): 280 Problem Description The math department has been having problems lately. Due to immense amount o…
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2041 Accepted Submission(s): 1047 Problem Description The math department has been having problems lately. Due to immense amount of unsolic…
The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-Test-to-Tell-Computers-and-Humans-Apart on their webpag…
<题目链接> 题目大意: The task that is presented to anyone visiting the start page of the math department is as follows: given a natural n, compute  where [x] denotes the largest integer not greater than x. 给出 t 和n,t代表样例组数,根据给出的n算出上面表达式.(注意:[x]表示,不超过x的最大整数)…
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care about each other.Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 time as large as its original siz…
题意就是叫你求上述那个公式在不同N下的结果. 思路:很显然的将上述式子换下元另p=3k+7则有 Σ[(p-1)!+1/p-[(p-1)!/p]] 接下来用到一个威尔逊定理,如果p为素数则 ( p -1 )! ≡ -1 ( mod p )    即 (p-1)!+1  为 p的整数倍  因此不难发现[*]里面要么为0,要么为1,为1的情况就是p为素数的情况,然后统计k=1-n中 有多少个3*k+1素数就好了 #include <iostream> #include <cstdio>…
Fansblog Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3170 Accepted Submission(s): 671 Problem Description Farmer John keeps a website called 'FansBlog' .Everyday , there are many people visite…
YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 875    Accepted Submission(s): 458 Problem Description The math department has been having problems lately. Due to immense amount of uns…
YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1490    Accepted Submission(s): 811 Problem Description The math department has been having problems lately. Due to immense amount of uns…
参考博客:https://blog.csdn.net/birdmanqin/article/details/97750844 题目链接:链接:http://acm.hdu.edu.cn/showproblem.php?pid=6608   威尔逊定理:在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件.即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操作意义不大. 题意:T组样例.每组样例,给出一个素数P(1e…
转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 219    Accepted Submission(s): 144 Problem Description Tina Town i…
参考博客 HDU-2973 题目 Problem Description The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-Test-to-Tell-Compu…
Problem Description Farmer John keeps a website called ‘FansBlog’ .Everyday , there are many people visited this blog.One day, he find the visits has reached P , which is a prime number.He thinks it is a interesting fact.And he remembers that the vis…
题意 给定一个整数 $P$($10^9 \leq p\leq 1^{14}$),设其前一个质数为 $Q$,求 $Q!  \ \% P$. 分析 暴力...说不定好的板子能过. 根据威尔逊定理,如果 $p$ 为质数,则有 $(p-1)! \equiv p-1(mod \ p)$. $\displaystyle Q! = \frac{(P-1)!}{(Q+1)(Q+2)...(p-1)} \equiv  (p-1)*inv\ (mod \ P)$. 根据素数定理,$\displaystyle \pi…
威尔逊定理 在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件.即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p ),但是由于阶乘是呈爆炸增长的,其结论对于实际操作意义不大. 充分性 如果“p”不是素数,那么它的正因数必然包含在整数1, 2, 3, 4, … ,p− 1 中,因此gcd((p− 1)!,p) > 1,所以我们不可能得到(p− 1)! ≡ −1 (modp).   必要性   若p是素数,取集合 A={1,2,3,...p -1}; 则A 构成…
题意:给定质数p,求q!模p的值,其中q为小于p的最大质数 1e9<=p<=1e14 思路:根据质数密度近似分布可以暴力找q并检查 找到q后根据威尔逊定理: 把q+1到p-1这一段的逆元移过去 #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,…
Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1)...*(Q-1)的逆元)%P.数据很大,用__int128. 代码如下 #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; inline int read(){ in…
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ball called zball. Zball is magic. It grows lar…
威尔逊原理.即对于素数p,有(p-1)!=-1( mod p). 首先,将原式变形为[ (3×k+6)! % (3×k+7) + 1] / (3×k+7),所以: 1.3×k+7是素数,结果为1, 2.3×k+7不是素数,则假设(3×k+7)=m1*m2*m3……,可知m1,m2,m3……<=3*k+6,则此时(3×k+6)! % (3×k+7) = 0,所以经过取整,式子的答案为0. #include<cstdio> using namespace std; ],sum[]; void…
题目链接:Lucky7 题意:求在l和r范围内,满足能被7整除,而且不满足任意一组,x mod p[i] = a[i]的数的个数. 思路:容斥定理+中国剩余定理+快速乘法. (奇+ 偶-) #include <stdio.h> #include <string.h> #include <iostream> using namespace std; #define LL long long #define FOR(i, n) for (int i=0; i<n; +…
此题往后推几步就可找到规律,从1开始,答案分别是1,2,4,8,16.... 这样就可以知道,题目的目的是求2^n%Mod的结果.....此时想,应该会想到快速幂...然后接着会发现,由于n的值过大,很容易就会T掉... 所以这个时候就想到找规律...试试就可以知道,1e9+6的时候是循环节... 然后用同余定理,把余数求出来就可以了... #include<iostream> #include<string> #include<string.h> #include&l…
The Designer Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 761    Accepted Submission(s): 142 Problem Description Nowadays, little haha got a problem from his teacher.His teacher wants to desi…
LINK 题意:一个大圆中内切两个圆,三个圆两两相切,再不断往上加新的相切圆,问加上的圆的面积和.具体切法看图 思路:笛卡尔定理: 若平面上四个半径为r1.r2.r3.r4的圆两两相切于不同点,则其半径满足以下结论: (1)若四圆两两外切,则    (2)若半径为r1.r2.r3的圆内切于半径为r4的圆中,则    显然现在是第二种情况,设弧度为$k$则,$r_1,r_2,r_3,r_4$的弧度为$k_1,k_2,k_3,k_4$,其中$r_4$是下个我们要求的圆的半径,显然我们已知前三个圆,第…
Invoker Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 122768/62768K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 0 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description On of Vance's favourite hero i…
http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后总的子集数目是2^n,减去不合法的,暴力枚举即可. 选了1个肯定不合法,2个也是,3个的话C(n, 3)枚举判断,C(n, 4), C(n, 5) #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false) using name…
题意:在杨辉三角中让你从最上面到 第 n 行,第 m 列所经过的元素之和最小,只能斜向下或者直向下走. 析:很容易知道,如果 m 在n的左半部分,那么就先从 (n, m)向左,再直着向上,如果是在右半部分,那么就是先向左斜着走再向上.这样对应到, 然后化简得到的答案就是C(n+1, m) + n - m,和C(n+1, m+1) + m.然后用Lucsa 定理就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000"…
Saving Beans Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5761    Accepted Submission(s): 2310 Problem Description Although winter is far away, squirrels have to work day and nig…
从6点看到10点,硬是没算出来,早知道玩游戏去了,艹,明天继续看 不爽,起来再看,终于算是弄懂了,以后超过一个小时的题不会再看了,不是题目看不懂,是水平不够 #include<cstdio> using namespace std; __int64 result,d; int flag; __int64 gcd(__int64 a,__int64 b,__int64 &x,__int64 &y) { __int64 t,ret; if(!b) { x = ; y = ; ret…