zoukankan      html  css  js  c++  java
  • CF900D Unusual Sequences

    题解

    首先显然若 (x mid y) 则无解。否则,令 (ygets frac{y}{x})

    (f_{k,g}) 为选若干个数 (langle a_{i=1}^n angle) 使得 (sum_{i=1}^n a_i=k)(gmid gcd(a_1,a_2,dots,a_n)) 的方案数。由组合恒等式易得若 (gmid k)(f_{k,g}=2^{k/g-1}),否则 (=0)

    所以 (f) 中只有 (operatorname{d}(y)) 个位置有值,(operatorname{d}) 是约数个数函数。

    加个光速幂,暴力转移即可,时间复杂度 (mathcal{O}([operatorname{d}(y)]^2)),不知道为啥跑得挺快。

    代码

    #include <cstdio>
    #include <cstring>
    #include <cctype>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    using namespace std;
    #define For(Ti,Ta,Tb) for(int Ti=(Ta);Ti<=(Tb);++Ti)
    #define Dec(Ti,Ta,Tb) for(int Ti=(Ta);Ti>=(Tb);--Ti)
    template<typename T> void Read(T &_x){
    	_x=0;int _f=1;
    	char ch=getchar();
    	while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();
    	while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();
    	_x*=_f;
    }
    template<typename T,typename... Args> void Read(T &_x,Args& ...others){
    	Read(_x);Read(others...);
    }
    typedef long long ll;
    typedef pair<int,ll> pil;
    const int Mod=1e9+7;
    template<int _V> struct FastPower{
    	static const int _Size=sqrt(_V+.5)+1;
    	long long _pow1[_Size],_pow2[_Size];
    	const int _Base,_Mod;
    	FastPower(int _base,int _mod):_Base(_base),_Mod(_mod){
    		_pow1[0]=_pow2[0]=1;
    		for(int _i=1;_i<_Size;++_i)
    			_pow1[_i]=_pow1[_i-1]*_Base%_Mod;
    		long long _temp=_pow1[_Size-1]*_Base%_Mod;
    		for(int _i=1;_i<_Size;++_i)
    			_pow2[_i]=_pow2[_i-1]*_temp%_Mod;
    	}
    	long long operator()(int _p){
    		return _pow1[_p%_Size]*_pow2[_p/_Size]%_Mod;
    	}
    };
    ll x,y;
    vector<pil> d;
    int main(){
    	Read(x,y);
    	if(y%x) return puts("0"),0;
    	y/=x,x=1;
    	FastPower<Mod> pow2(2,Mod);
    	for(int i=1;i*i<=y;++i){
    		if(y%i==0) d.push_back({i,pow2(y/i-1)}),d.push_back({y/i,pow2(i-1)});
    	}
    	sort(d.begin(),d.end());
    	d.erase(unique(d.begin(),d.end()),d.end());
    	d.insert(d.begin(),{0,0});
    	for(auto it=prev(d.end());it!=d.begin();--it){
    		for(auto jt=next(it);jt!=d.end();++jt){
    			if(jt->first%it->first==0)
    				it->second=(it->second+Mod-jt->second)%Mod;
    		}
    	}
    	printf("%lld
    ",d[1].second);
    	return 0;
    }
    
    Written by Alan_Zhao
  • 相关阅读:
    【科普杂谈】计算机按下电源后发生了什么
    【VS开发】使用WinPcap编程(1)——获取网络设备信息
    【VS开发】使用WinPcap编程(1)——获取网络设备信息
    微信公众平台消息接口PHP版
    编码gbk ajax的提交
    mysql 查询
    js cookie
    js同域名下不同文件下使用coookie
    去掉A标签的虚线框
    jquery切换class
  • 原文地址:https://www.cnblogs.com/alan-zhao-2007/p/cf900d-sol.html
Copyright © 2011-2022 走看看