HDU-6608-Fansblog(威尔逊定理+快速乘)(多校)
Then T line follows, each contains a positive prime number P (1e9≤p≤1e14)
1000000007
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath> typedef long long ll;
using namespace std;
int prime[];
bool vis[];
int cnt =;
void erla() {
memset(vis,false,sizeof(vis));
memset(prime,,sizeof(prime));
for(int t=; t<=; t++) {
if(!vis[t]) {
prime[cnt++]=t;
}
for(int j=; j<cnt&&t*prime[j]<=; j++) {
vis[t*prime[j]]=true;
if(t%prime[j]==) {
break;
}
}
}
}
inline ll ksc(ll x,ll y,ll mod)
{
return (x*y-(ll)((long double)x/mod*y)*mod+mod)%mod;
}
ll ksm(ll x,ll y,ll mod)
{
ll ans=;
while(y)
{
if(y&)
{
ans=ksc(ans,x,mod);
}
x=ksc(x,x,mod);
y>>=;
}
return ans;
}
bool isprime(ll x)
{
for(int t=;t<cnt&&prime[t]<x;t++)
{ if(x%prime[t]==)
{
return false;
}
}
return true;
}
int main()
{
int T;
cin>>T;
erla();
while(T--)
{
ll n;
scanf("%lld",&n);
ll ans=;
for(ll t=n-;t>=;t--)
{
if(isprime(t))
{
break;
} ans=ksc(ans,ksm(t,n-,n),n);
//cout<<ans<<endl;
}
printf("%lld\n",ans); }
return ;
}
HDU-6608-Fansblog(威尔逊定理+快速乘)(多校)的更多相关文章
- 2019HDU多校第三场F Fansblog——威尔逊定理&&素数密度
题意 给定一个整数 $P$($10^9 \leq p\leq 1^{14}$),设其前一个质数为 $Q$,求 $Q! \ \% P$. 分析 暴力...说不定好的板子能过. 根据威尔逊定理,如果 $ ...
- 2019杭电多校第三场hdu6608 Fansblog(威尔逊定理)
Fansblog 题目传送门 解题思路 Q! % P = (P-1)!/(P-1)...(Q-1) % P. 因为P是质数,根据威尔逊定理,(P-1)!%P=P-1.所以答案就是(P-1)((P-1) ...
- hdu 2973"YAPTCHA"(威尔逊定理)
传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...
- HDU 6608:Fansblog(威尔逊定理)
Fansblog Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- HDU-6608 Fansblog(威尔逊定理+素数间隔+逆元)
参考博客:https://blog.csdn.net/birdmanqin/article/details/97750844 题目链接:链接:http://acm.hdu.edu.cn/showpro ...
- 组合数(Lucas定理) + 快速幂 --- HDU 5226 Tom and matrix
Tom and matrix Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analy ...
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- HDU - 2973:YAPTCHA (威尔逊定理)
The math department has been having problems lately. Due to immense amount of unsolicited automated ...
- HDU 2973 YAPTCHA (威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- Windows聚焦失效问题的解决办法
1. 设置Windows聚焦 步骤:任务栏右键 → 任务栏设置 → 锁屏界面 → 背景选择Windows聚焦 2. 解决Windows聚焦失效问题 设置完Windows聚焦之后,锁屏界面却没有变. 尝 ...
- 搭建 springboot selenium 网页文件转图片环境
1. 环境准备 需要有 chrome 浏览器 + chrome driver + selenium 客户端 离线 chrome 下载地址 # 64位 linux 系统 https://dl.googl ...
- Python中 *args 和 **kwargs 的含义?
答:在python中,*args和**kwargs通常使用在函数定义里.*args 和 **kwargs 都允许你给函数传不定数量的参数,即使在定义函数的时候不知道调用者会传递几个参数.ps: *ar ...
- C# ASP 分析器错误信息: 无法识别的属性“targetFramework”。请注意属性名称区分大小写。
在本地运行的应用,部署到服务器上出现错误.原因是web.config 中:<compilation debug="true" targetFramework="4. ...
- C#设计模式之0-简单工厂模式
简单工厂模式(Simple Factory Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/387 访问 ...
- C#LeetCode刷题之#876-链表的中间结点(Middle of the Linked List)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3836 访问. 给定一个带有头结点 head 的非空单链表,返回链 ...
- day1 linux常用命令(一)
- 什么是c/c++编译
GCC是什么 GNU Compiler Collection的缩写,一开始是c语言的编译器,但现今可以支持多种语言的编译工作,也支持了多个硬件平台的编译.总而言之,主流的c语言编译器就是这个gcc了. ...
- Git操作之码云代码clone
安装Git https://git-scm.com/book/zh/v2/起步-安装-Git Git的网站上有详细的分各种系统的安装教程. 配置Git 1. 打开你要放置项目的本地路径,右键选择$ G ...
- Android ActivityResumeTrigger: not whiteListed
在点击返回按钮的时候报错: ActivityResumeTrigger: not whiteListed 合作者写的返回操作是: findViewById(R.id.lin_back).setOnTo ...