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

    题目大意

    给定 (x,y) ,求有多少个数列满足其 (gcd)(x) ,和为 (y)

    题解

    (k=x/y),若 (k) 不是整数则无解。否则就是求和为 (k)(gcd=1) 的序列个数

    容斥考虑:

    首先和为 (k) 的所有序列一共有(2^{k-1}) 个。

    (gcd!=1) 则应减去,我们枚举 (gcd) 并将序列每个数除去 (gcd) 后,又回到了原问题。

    递归解决即可。

    #include<iostream>
    #include<map>
    #define LL long long
    using namespace std;
    LL x, y;
    const int mod = 1e9 + 7;
    map<int, int>mp;
    LL ksm(LL a, LL b, LL mod)
    {
    	LL res = 1;
    	for (; b; b >>= 1, a = a * a % mod)
    		if (b & 1)res = res * a % mod;
    	return res;
    }
    LL dfs(int x)
    {
    	if (mp.count(x))return mp[x];
    	if (x == 1)return mp[x] = 1;
    	LL res = ksm(2, x - 1, mod);
    	for (int i = 1; i * i <= x; ++i)
    		if (x % i == 0)
    		{
    			if (i == 1 || i * i == x)(res -= dfs(i)) %= mod;
    			else (res -= dfs(i) + dfs(x / i)) %= mod;
    		}
    	return mp[x] = (res % mod + mod) % mod;
    }
    int main()
    {
    	cin >> x >> y;
    	if (y % x)return puts("0") == 2333;
    	cout << dfs(y / x);
    	return 0;
    }
    
  • 相关阅读:
    luffy后台登录+注册+课程
    luffy前台登录+注册+课程
    luffy前台准备
    luffy后台准备
    跨域请求
    pip源和虚拟环境的搭建
    Book接口
    drf-Xadmin的使用
    drf-JWT认证
    drf-自动生成接口文档
  • 原文地址:https://www.cnblogs.com/wljss/p/12589468.html
Copyright © 2011-2022 走看看