花
来源:互联网 发布:淘宝发布宝贝草稿箱 编辑:程序博客网 时间:2024/06/10 18:08
【问题描述】
商店里出售n种不同品种的花。为了装饰桌面,你打算买m支花回家。你觉得放两支一样的花很难看,因此每种品种的花最多买1支。求总共有几种不同的买花的方案?答案可能很大,输出答案mod p的值。
【输入格式】
一行3个整数n,m,p,意义如题所述。
【输出格式】
一个整数,表示买花的方案数。
【输入输出样例】
flower.in flower.out
4 2 5 1
【输入输出样例说明】
用数字1,2,3,4来表示花的种类的话,4种花里买各不相同的2支的方案有(1,2)、(1,3)、(1,4)、(2,3)、(2,4)、(3,4),共6种方案,模5后余数是1。
【数据范围】
对于30%的数据,n,m≤10
对于50%的数据,n,m≤1000
对于80%的数据,1≤m≤n≤50,000
对于100%的数据,1≤m≤n≤1,000,000,p≤1,000,000,000
一开始想的是直接算+求逆元
但是p不是质数
n , p也不互质
这样就没法求逆元
这样这个题的做法只剩下了一个
分解质因数
就是我在考场上写挂了的分解质因数
微笑中透着疲惫.jpg
然而写完还是超时
看了题解
加了个特判[或者说更应该叫剪枝?]
就过了
顺便
今天不能抽卡真是残念
连着试了三个模数
出来都是0
吓得我以为题解和自己都错了
最后发现没错
这个运气让我觉得
自己可能
错过了十个SSR_ (:з」∠)_
#include<iostream>#include<cstring>#include<algorithm>#include<cstdio>#include<queue>#include<vector>#include<climits>#include<string>#include<cstdlib>#include<ctime>#define MOD 1000000007#define LL long longusing namespace std;LL n,m,p,tot,prim[1000005],num[1000005];int f[1000005];void pre(){ LL i,j; for(i=2;i<=1000000;i++) { if(!f[i]) { tot++; prim[tot]=i; } for(j=1;(j<=tot)&&(prim[j]*i<=1000000);j++) { f[i*prim[j]]=1; if(i%prim[j]==0) break; } }}void work(LL l,LL r,LL t){ LL tmp,s,i; for(i=l;i<=r;i++) { tmp=i; s=1; while(tmp!=1) { if(!f[tmp]) { num[tmp]+=t; break; } while(tmp%prim[s]==0) { tmp/=prim[s]; num[prim[s]]+=t; } s++; } }}LL fastpow(LL x,LL t){ LL tmp=1; while(t!=1) { if(t%2==1) tmp=(tmp*x)%p; x=(x*x)%p; t/=2; } x=(x*tmp)%p; return x;}int main(){ freopen("flower.in","r",stdin); freopen("flower.out","w",stdout); LL i,ans,tmp; scanf("%lld%lld%lld",&n,&m,&p); pre(); work(m+1,n,1); work(2,n-m,-1); ans=1; for(i=2;i<=1000000;i++) if(num[i]!=0) { tmp=fastpow(i,num[i])%p; ans=(ans*tmp)%p; } printf("%lld",ans); return 0;}
阅读全文
0 0
- 花
- 花
- 花
- 花
- 花
- 花
- 《花》
- 花
- 花
- 花
- 花
- 花花的起步!!!
- 很花的花
- 秋天花花同学会
- 花花的森林
- 花花的森林
- 花花的聚会
- 花花的music1
- async和await
- sql server
- Python015面向对象之类和对象
- 深入分析根据字节取数据
- java刷题笔记-线程
- 花
- 【PAT】【Advanced Level】1123. Is It a Complete AVL Tree (30)
- GetModuleHandle
- UnicodeEncodeError: 'gbk' codec can't encode character: illegal multibyte sequence
- python设置编码格式utf-8
- 自己编写的两级队列的线程池(根据ThreadPoolExecuuor)
- 前端性能优化漫谈----用户
- 顺序 链式 索引 散列存储
- 从Dying gasp功能看Linux的响应速度