【CQ18高一暑假前挑战赛3.5】标程
【A:快速幂相关】
#include<bits/stdc++.h>
using namespace std;
int qpow(int a,int x){
a%=;int res=; while(x){
if(x&) res=res*a%;
a=a*a%; x>>=;
} return res;
}
int main()
{
int N;
cin>>N;
cout<<qpow(N,N);
return ;
}
【B:位数相关】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int qpow(int a,int x){
int res=; a%=; while(x){
if(x&) res=res*a%;
a=a*a%; x>>=;
}return res;
}
int main()
{
int T,Case=; ll N,K;
scanf("%d",&T);
while(T--){
scanf("%lld%lld",&N,&K);
double x=K*log10(N)-(ll)(K*log10(N));
x=pow(10.0,x);
printf("Case %d: %d %03d\n",++Case,(int)(100.0*x),qpow(N,K));
}
return ;
}
【C:Nim博弈相关】
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,x,ans=;
scanf("%d",&N);
while(N--){
scanf("%d",&x);
ans^=x;
}
if(!ans) puts("B");
else puts("A");
return ;
}
【D:分治相关】
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int Mod=1e9+;
ll qpow2(ll a,ll x){
ll res=; while(x){
if(x&) res=res*a%Mod;
a=a*a%Mod;x>>=;
}
return res;
}
ll qpow(ll N)
{
if(N==) return ;
ll res=;
if(N&){ res=qpow2(,N); N--; }
ll tmp=qpow(N/);
return (tmp+tmp*qpow2(,N/)%Mod+res)%Mod;
}
int main()
{
ll N,ans;
scanf("%lld",&N);
ans=(+qpow(N))%Mod;
printf("%lld\n",ans);
return ;
}
【E:组合数相关】Lucas+中国剩余定理
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int maxn=;
LL fac[maxn],mod[maxn],odd[maxn],M,Mod;
void factorial()
{
fac[]=; for(int i=;i<=Mod;i++) fac[i]=fac[i-]*i%Mod;
}
LL f_pow(LL a,LL x)
{
LL res=; a%=Mod;
while(x){ if(x&) res=res*a%Mod;a=a*a%Mod; x>>=; }return res;
}
LL C(LL n,LL m)
{
if(m>n) return ; return fac[n]*f_pow(fac[m]*fac[n-m]%Mod,Mod-)%Mod;
}
LL Lucas(LL n,LL m)
{
if(m==) return ; return C(n%Mod,m%Mod)*Lucas(n/Mod,m/Mod)%Mod;
}
LL mul(LL x,LL y,LL p)
{
LL res=;
while(y){
if(y&) res=(res+x)%p;y>>=;x=(x+x)%p;
}return res%p;
}
void China(int k)
{
LL ans=;
for(int i=;i<=k;i++){
Mod=mod[i];
ans=ans+mul(mul(M/mod[i],f_pow(M/mod[i],mod[i]-),M),odd[i],M);
//ans=ans+M/mod[i]*f_pow(M/mod[i],mod[i]-2)*odd[i]%M;
}printf("%lld\n",(ans+M)%M);
}
int main()
{
LL T,n,m,k;
scanf("%lld",&T);
while(T--){
M=;
scanf("%lld%lld%lld",&n,&m,&k);
for(int i=;i<=k;i++){
scanf("%d",&mod[i]);Mod=mod[i];M*=mod[i];
factorial();
odd[i]=Lucas(n,m)%Mod;
}
China(k);
}return ;
}
【CQ18高一暑假前挑战赛3.5】标程的更多相关文章
- 【CQ18高一暑假前挑战赛5】标程
[A:暴力] #include<bits/stdc++.h> using namespace std; ; int a[maxn],vis[maxn],N,M; int main() { ...
- 【CQ18高一暑假前挑战赛4】标程
[二分或者STL] 二分: #include<bits/stdc++.h> using namespace std; ; int a[maxn]; int main() { ,pos; s ...
- 【CQ18高一暑假前挑战赛3】标程
[A:LCM] #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll a,b, ...
- 【CQ18高一暑假前挑战赛2】标程
[昨晚打校赛,5个小时打完很累了,所以搞忘出题了...对不起学弟们,不过出的题都亲自写过一遍,可以保证题目和代码长度都不长,题目难度不大] [A:bush博弈] #include<bits/st ...
- 【CQ18高一暑假前挑战赛1】标程
[A] #include<bits/stdc++.h> using namespace std; #define ll long long ll qpow(ll a,ll x,ll Mod ...
- [转]关于一些SPFA的标程
SPFA算法 求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm. 最短路径快速算法-SPFA算法是西南交通大学段凡丁于1994年发表的. 适用范围:给定 ...
- [求助][SPOJ MARIOGAM]-高斯消元(内含标程,数据等)
小蒟蒻开始做概率的题之后,遇到了这道题,然而,他发现自己的程序调试了无数次也无法通过,系统总是返回令人伤心的WA, 于是,他决定把这一天半的时间收集到的资料放在网上, 寻求大家的帮助, 也可以节省后来 ...
- hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板
比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...
- 暑假前的flag
暑假到了,为了简便新开了一个博客,供暑假刷体放一些题解,玩acm1年多了,cf还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...
随机推荐
- 使用cacheBuilder实现函数防抖
在接口中出现的相同请求重复且连续发送的情况导致一些业务BUG,需要在接口上实现防抖 使用google的cacheBuilder import com.google.common.cache.Cache ...
- odoo多币种
配置 启用多币种特性,并设置本位币 Gain exchange rate account 汇损收益科目,一般为财务费用下的二级科目 Loss exchange rate account 汇损损 ...
- SpringMVC:JSON
@ResponseBody params="json":访问我这个方法的时候一定要有参数名为json 返回值Userjackson-all-1.9.0.jar @RequestMa ...
- 网络通讯框架MINA和XSCOCKET的简单比较
http://www.blogjava.net/ghostdog/archive/2008/06/10/MinaVsXsocket.html实在无聊,考虑把当前应用的通讯模式由http移植为socke ...
- hdu 5316 Magician 线段树
链接:http://acm.hdu.edu.cn/showproblem.php? pid=5316 Magician Time Limit: 18000/9000 MS (Java/Others) ...
- cocos2d-x项目101次相遇:在HelloWorld上--建立新场景
cocos2d-x 101次相遇 / 文件夹 1 安装和环境搭建 -xcode 2 Scenes , Director, Layers, Sprites 3 建立图片菜单 4 在 ...
- pyqt5 学习总结
关于基类 一般的文件都会基于QWidget,QtWidgets.QMainWindow 或QDialog,like this class Example(QWidget): QWidget类是所有用户 ...
- 在Fedora 23上安装多媒体解码器
在Fedora 23上安装多媒体解码器 时间:2016-06-25来源:topspeedsnail.com 作者:斗大的熊猫 安装多媒体解码器允许你播放更多格式的音频和视频格式.大多数这些解码器都 ...
- Python使用Mysql过程中一些错误
Python使用Mysql过程中一些错误 ssh登录远程服务器 ssh ubuntu@xxx.xxx.xx.xx 第一:ubuntu终端中登录Mysql mysql -uroot -p 然后输入密码即 ...
- 我们将要建立的EasyDarwin开源社区
从12年12月我开始建立EasyDarwin开源项目,已经三年多的时间了,从开始最简单的一个开源流媒体服务器项目,如今已经发展成为目前国内最大的一个流媒体开源社区,截至目前已经有十几个项目在Githu ...