题解:
看到和式的时候就想到了插板法,然后我们需要剔除因子为gcd的倍数的情况,就比如我们在隔板(3,3,3,3)的时候算方案为 2 3 2^3 23已经把(6,6)这种情况算了,但是这个是不满足的。所以我们在筛m的因子时候特判一下是否有因子能够整除n,如果能就需要减去。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include <bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; const int N=1e5+10; int f[N]; vector<int> fac; int qmi(int a,int b) { int res=1; while(b){ if(b&1) res=res*a%mod; a=a*a%mod; b>>=1; } return res; } void solve(){ int n,m; scanf("%lld%lld",&n,&m); if(m%n) { puts("0"); return; } for(int i=1;i<=sqrt(m);i++){ if(m%i==0){ if(i%n==0) fac.push_back(i); if(i*i!=m&&m/i%n==0) fac.push_back(m/i); } } sort(fac.begin(),fac.end(),greater<int>()); for(int i=0;i<fac.size();i++){ f[i]=qmi(2,m/fac[i]-1); for(int j=i-1;j>=0;j--){ // cout<<"----" << fac[i]<<' '<<fac[j] << endl; if(fac[j]%fac[i]==0) f[i]=(f[i]-f[j]+mod)%mod; } } cout<<f[fac.size()-1]<<endl; } signed main(){ solve(); #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.n"; #endif return 0; }
最后
以上就是老实眼睛最近收集整理的关于D. Unusual Sequences题解:的全部内容,更多相关D.内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复