Codeforces Round #716 (Div. 2)
题意:
给几个数,判断他们的乘积是否为完全平方数,如果是就输出NO,不是就输出YES
思路:
因为要想他们的乘积为完全平方数,则每一个数都应该改为完全平方数,因此判断每一个数是否为完全平方数即可。
#include <iostream> #include <cmath> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; bool flag = true; for (int i = 1; i <= n; i++) { int x; cin >> x; if (sqrt(x) != (int)sqrt(x)) flag = false; } if (flag) puts("NO"); else puts("YES"); } return 0; }
题意:
构造一个含n个k位二进制数的序列,满足条件:序列中所有数按位与为0,且序列和尽可能大,求构造方案数
思路:

用快速幂
#include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; LL quick_mod(LL a , LL b , LL MOD = 1e9 + 7) { LL res = 1 % MOD; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; cout << quick_mod(n, k) << endl; } return 0; }

浙公网安备 33010602011771号