D. Madoka and the Best School in Russia(因子背包, 完全背包, 大数值不带log的离散化)

//https://codeforces.com/problemset/problem/1647/D
#include<bits/stdc++.h>
#include<unordered_map>
#include<array>
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const ll mod = 998244353;
const int N = 1e5 + 5;

/*
定义一个数是d的倍数,不是d*d的倍数, 则为完美数
问x是否可以表示为一些完美数的乘积,且方案数大于等于二
*/

ll x, d, id[N], gid[N];
ll f[N];
vector<ll> fac, bea;

void solve()
{
	cin >> x >> d;
	
	fac.clear();
	bea.clear();
	for (ll i = 1; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			fac.push_back(i);
			if (x / i != i)
				fac.push_back(x / i);
		}
	}
	sort(all(fac));
	for (int it : fac)//完美数
		if (it % d == 0 && it / d % d)
			bea.push_back(it);

	for (int i = 0; i < fac.size(); i++)//离散化, 分成一大一小两个数组, 因为正常离散化或者map复杂度高
	{
		if (fac[i] < N)
			id[fac[i]] = i;
		else
			gid[x / fac[i]] = i;
	}

	for (int i = 0; i < fac.size(); i++)
		f[i] = 0;
	f[0] = 1;
	for (int i : bea)
	{
		for (int j : fac)//完全背包
		{
			if (x / i % j == 0)//i * j 是x的因子
			{
				int temp = i * j;
				int idx1 = (temp < N ? id[temp] : gid[x / temp]);//离散
				int idx2 = (j < N ? id[j] : gid[x / j]);
				f[idx1] = f[idx1] + f[idx2];
			}
		}
	}
	int idx = (x < N ? id[x] : gid[1]);
	cout << (f[idx] >= 2 ? "YES" : "NO") << '\n';
}

signed main()
{
	IOS;
	int t = 1;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

以下是截至2021年10月的全球动漫评分排行榜前100名: 1.《Fullmetal Alchemist: Brotherhood》 2.《Steins;Gate》 3.《Your Lie in April》 4.《Hunter x Hunter (2011)》 5.《Gintama》 6.《Haikyuu!!》 7.《Attack on Titan》 8.《Code Geass: Lelouch of the Rebellion》 9.《Clannad: After Story》 10.《Death Note》 11.《One Punch Man》 12.《Jojo's Bizarre Adventure》 13.《Cowboy Bebop》 14.《Baccano!》 15.《Neon Genesis Evangelion》 16.《Spirited Away》 17.《Monogatari Series》 18.《Shigatsu wa Kimi no Uso》 19.《Toradora!》 20.《Tengen Toppa Gurren Lagann》 21.《K-On!》 22.《The Melancholy of Haruhi Suzumiya》 23.《Fate/Zero》 24.《One Piece》 25.《Rurouni Kenshin: Trust and Betrayal》 26.《Dragon Ball Z》 27.《Legend of the Galactic Heroes》 28.《Hajime no Ippo》 29.《Ghost in the Shell: Stand Alone Complex》 30.《Nana》 31.《Samurai Champloo》 32.《Great Teacher Onizuka》 33.《Anohana: The Flower We Saw That Day》 34.《Kimi no Na wa.》 35.《Kara no Kyoukai》 36.《Psycho-Pass》 37.《Bakemonogatari》 38.《No Game No Life》 39.《Nichijou》 40.《Usagi Drop》 41.《Kill la Kill》 42.《Akira》 43.《Durarara!!》 44.《Tatami Galaxy》 45.《Katanagatari》 46.《Berserk》 47.《Princess Mononoke》 48.《Higurashi no Naku Koro ni》 49.《Soul Eater》 50.《Black Lagoon》 51.《Naruto》 52.《Fairy Tail》 53.《Kimi ni Todoke》 54.《Serial Experiments Lain》 55.《Kuroko no Basket》 56.《Chihayafuru》 57.《Hyouka》 58.《Bleach》 59.《Sakamichi no Apollon》 60.《Golden Time》 61.《Love Live! School Idol Project》 62.《Cardcaptor Sakura》 63.《Gekkan Shoujo Nozaki-kun》 64.《Full Metal Panic!》 65.《Mobile Suit Gundam: Iron-Blooded Orphans》 66.《K-On! Movie》 67.《Kizumonogatari》 68.《Re:Zero kara Hajimeru Isekai Seikatsu》 69.《Shirobako》 70.《Yahari Ore no Seishun Love Comedy wa Machigatteiru.》 71.《Darker than Black》 72.《Honey and Clover》 73.《Zankyou no Terror》 74.《Usagi Drop Specials》 75.《Mahou Shoujo Madoka★Magica》 76.《Bungou Stray Dogs》 77.《Kara no Kyoukai 5: Mujun Rasen》 78.《K-On! 2》 79.《Toaru Kagaku no Railgun》 80.《Kimi ga Nozomu Eien》 81.《Grisaia no Kajitsu》 82.《Gochuumon wa Usagi Desu ka?》 83.《Shinsekai yori》 84.《Nodame Cantabile》 85.《Bungou Stray Dogs 2nd Season》 86.《Made in Abyss》 87.《Gin no Saji》 88.《Ranma ½》 89.《K-On!!》 90.《Sword Art Online》 91.《Hibike! Euphonium》 92.《Nisekoi》 93.《K-On!: Live House!》 94.《K-On!: Keikaku!》 95.《D-Frag!》 96.《K-On!: Ura-ON!》 97.《K-On!: College》 98.《K-On!: Fude Pen - Boru Pen》 99.《K-On!: Plan!》 100.《K-On!: Movie - Wonderful♪》
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值