洛谷 - p2651 添加括号III(思维,数学)

    技术2022-07-11  97

    题目传送 题意: 思路: 我们首先想想如何判断一个分数是否能约分成整数 判断方法: (1)我们可以分解分子的质因子和分母的质因子,如果分母的质因子数量和种类数完全被分子的质因子包括,那么一定可以约分成为整数

    (2)如果分母的所有因子都包含在分子的因子中如:10 和 20。10中的1 2 5 10都也是20的因子 。那么也是可以被约分成为整数

    (3)分子与分母的最大公约数为分母本身,那么也可以判断 等等…

    回归本题: 假如给了a1 / a2 / a3 … / an 那么我们可以观察到a1必然是分子(因为前面没有数),a2必然会成为分母(如果有超能力可以试试),那么依据前面的(2)中的判断方法,我们肯定要使得分子的因子种数尽肯能的多,才机会越大,那么如何达到最多呢?那么我们直接a1 / (a2 / a3 / a4 … an),a2后面的数都将成为分子,那么就使得分子的因子种数最大化,分母的因子种数最小化。但是为了避免打高精,根据(3)我们可以让a2每次除以其他所有数最大公约数,如果最后为1,那么说明分母的因子被分子全部包括

    AC代码

    #include <bits/stdc++.h> inline long long read(){char c = getchar();long long x = 0,s = 1; while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();} while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();} return x*s;} using namespace std; #define NewNode (TreeNode *)malloc(sizeof(TreeNode)) #define Mem(a,b) memset(a,b,sizeof(a)) #define lowbit(x) (x)&(-x) const int N = 1e5 + 10; const long long INFINF = 0x7f7f7f7f7f7f7f; const int INF = 0x3f3f3f3f; const double EPS = 1e-7; const double EEE = exp(1); const int mod = 1e9+7; const double II = acos(-1); const double PP = (II*1.0)/(180.00); typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> piil; signed main() { std::ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int t; cin >> t; while(t--) { int n,a,b; cin >> n >> a >> b; b /= __gcd(a,b),n -= 2; while(n--) { cin >> a; b /= __gcd(a,b); } b == 1 ? cout << "Yes" << endl : cout << "No" << endl; } }
    Processed: 0.018, SQL: 9