結果

問題 No.1556 Power Equality
ユーザー tpc011854tpc011854
提出日時 2021-06-25 22:43:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 851 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 55,200 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 14:47:28
合計ジャッジ時間 1,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
struct Element {
	long long u;
	long long cnt;
};
std::vector<Element> getFactor(long long n){
	std::vector<Element> res;
	for(long long i = 2; i*i <= n; i++){
		if(n == 1) break;
		if(n%i==0){
			int cnt = 0;
			while(n%i==0){
				n /= i;
				cnt++;
			}
			res.push_back({i, cnt});
		}
	}
	if(n!=1) res.push_back({n, 1});
	std::sort(res.begin(), res.end(), [](Element& u, Element& v){
		return u.u < v.u;
	});
	return res;
}


int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	std::vector<Element> fa = getFactor(a);
	std::vector<Element> fb = getFactor(b);
	int ok = 1;
	if(fa.size()!=fb.size()) ok = 0;
	for(int i = 0; i < (int)fa.size(); i++){
		if(fa[i].u!=fb[i].u)
			ok = 0;
		if(fa[i].u*b!=fb[i].u*a)
			ok = 0;
	}
	if(ok)
		printf("Yes\n");
	else 
		printf("No\n");
	return 0;
}
0