题意 给定一个整数 $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…
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…
传送门 题意: 给出自然数 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…
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…
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…
参考博客: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…
Tom and matrix Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analyse: 直接可以用Lucas定理+快速幂水过的,但是我却作死的用了另一种方法. 方法一:Lucas定理+快速幂水过 方法二:首先问题可以转化为求(0,0),(n,m)这个子矩阵的所有数之和.画个图容易得到一个做法,对于n<=m,答案就是2^0+2^1+...+2^m=2^(m+1)-1,对于n>m…
<题目链接> 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…
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…
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…
题意:给定质数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,…
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…
转载请注明出处: 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…
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…
<题目链接> 题目大意: 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的最大整数)…
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…
题意就是叫你求上述那个公式在不同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>…
参考博客 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…
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…
HDU.1575 Tr A ( 矩阵快速幂) 点我挑战题目 题意分析 直接求矩阵A^K的结果,然后计算正对角线,即左上到右下对角线的和,结果模9973后输出即可. 由于此题矩阵直接给出的,题目比较裸. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #…
威尔逊定理 在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件.即:当且仅当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 构成…
斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5)/2)^n)/√5 假设F[n]可以表示成 t * 10^k(t是一个小数),那么对于F[n]取对数log10,答案就为log10 t + K,此时很明显log10 t<1,于是我们去除整数部分,就得到了log10 t 再用pow(10,log10 t)我们就还原回了t.将t×1000就得到了F[n…
Sum Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=4704 Mean: 给定一个大整数N,求1到N中每个数的因式分解个数的总和. analyse: N可达10^100000,只能用数学方法来做. 首先想到的是找规律.通过枚举小数据来找规律,发现其实answer=pow(2,n-1); 分析到这问题就简单了.由于n非常大,所以这里要用到费马小定理:a^n ≡ a^(n%(m-1)) * a^(m-1)≡ a^(n%(m-…
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=4704 Problem Description   Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input file consists of multiple test cases.   题意是输入一个N,求N被分成1个数的结果+被分成2个数的结果+...+被分成N个数的结果,N很大   1.隔板原…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到了一个数列: fn= 1,ab,abfcn−1fn−2,n=1n=2otherwise 给定各个数,求fn. 分析: 可以发现最后都是a的倍数,这样我们让fn对a取对数,令tn=logafn方程就转化为b+ctn−1+tn−2,这样利用矩阵快速幂直接算幂数,最后快速幂一下就可以了. 注意: 由费马小…
题目链接 题意 : m张牌,可以翻n次,每次翻xi张牌,问最后能得到多少种形态. 思路 :0定义为反面,1定义为正面,(一开始都是反), 对于每次翻牌操作,我们定义两个边界lb,rb,代表每次中1最少时最少的个数,rb代表1最多时的个数.一张牌翻两次和两张牌翻一次 得到的奇偶性相同,所以结果中lb和最多的rb的奇偶性相同.如果找到了lb和rb,那么,介于这两个数之间且与这两个数奇偶性相同的数均可取到,然后在这个区间内求组合数相加(若lb=3,rb=7,则3,5,7这些情况都能取到,也就是说最后的…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4633 典型的Polya定理: 思路:根据Burnside引理,等价类个数等于所有的置换群中的不动点的个数的平均值,根据Polya定理,不动点的个数等于Km(f),m(f)为置换f的循环节数,因此一次枚举魔方的24中置换,人肉数循环节数即可,注意细节,别数错了. 1.静止不动,(顶点8个循环,边12个循环,面54个循环) 2.通过两个对立的顶点,分别旋转120,240,有4组顶点,(点4个循环,边4个…
此题往后推几步就可找到规律,从1开始,答案分别是1,2,4,8,16.... 这样就可以知道,题目的目的是求2^n%Mod的结果.....此时想,应该会想到快速幂...然后接着会发现,由于n的值过大,很容易就会T掉... 所以这个时候就想到找规律...试试就可以知道,1e9+6的时候是循环节... 然后用同余定理,把余数求出来就可以了... #include<iostream> #include<string> #include<string.h> #include&l…
题意: 这题意看了很久.. s(k)表示的是把n分成k个正整数的和,有多少种分法. 例如: n=4时, s(1)=1     4 s(2)=3     1,3      3,1       2,2 s(3)=3     1,1,2         1,2,1       2,1,1 s(4)=1       1,1,1,1 s(1)+s(2)+s(3)+s(4)=1+3+3+1=8 当n=1,2,3,4时,可以分别求出结果为    1,2,4,8 于是推出答案就是2^(n-1)---------…
链接:传送门 题意:求 N 的拆分数 思路: 吐嘈:求一个数 N 的拆分方案数,但是这个拆分方案十分 cd ,例如:4 = 4 , 4 = 1 + 3 , 4 = 3 + 1 , 4 = 2 + 2 , 4 = 1 + 1 + 2 , 4 = 1 + 2 + 1 , 4 = 2 + 1 + 1 , 4 = 1 + 1 + 1 + 1,共 8 种,你没有看错,这跟普通概念上的拆分数有很大的不同,拆分数不考虑顺序,即 4 = 1 + 3 与 4 = 3 + 1 是相同的,及其坑爹,所以可以发现 N…