zoukankan      html  css  js  c++  java
  • Coderforce-574C Bear and Poker(素数唯一分解定理)

    题目大意:给出n个数,问能不能通过让所有的数都乘以2的任意幂或乘以3的任意幂,使这n个数全都相等。

    题目分析:最终n个数都是相等的,假设那个数为x,根据素数唯一分解定理,x能分解成m*2p3q。所以,只需将所有的a[i]一直除以2并且一直除以3,最终只需判断这n个数是否全部相等即可。

    代码如下:

    # include<iostream>
    # include<cstdio>
    # include<cmath>
    # include<string>
    # include<vector>
    # include<list>
    # include<set>
    # include<map>
    # include<queue>
    # include<cstring>
    # include<algorithm>
    using namespace std;
    
    # define LL long long
    # define REP(i,s,n) for(int i=s;i<n;++i)
    # define CL(a,b) memset(a,b,sizeof(a))
    # define CLL(a,b,n) fill(a,a+n,b)
    
    const double inf=1e30;
    const int INF=1<<30;
    const int N=100005;
    
    int n;
    LL a[N];
    
    void f(LL &k)
    {
        while(k%2==0) k/=2;
        while(k%3==0) k/=3;
    }
    
    bool judge()
    {
        REP(i,1,n) if(a[i]!=a[0]) return false;
        return true;
    }
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            REP(i,0,n){
                scanf("%lld",a+i);
                f(a[i]);
            }
            if(judge()) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    小程序开发学习
    guava 学习一 函数,集合操作
    《构建之法》第四章 两人合作 读后感
    模拟退火学习笔记
    Haywire
    [JSOI2004]平衡点
    CF1039D You Are Given a Tree
    CF797E Array Queries
    [SHOI2014]三叉神经树
    [国家集训队]Tree II
  • 原文地址:https://www.cnblogs.com/20143605--pcx/p/5090189.html
Copyright © 2011-2022 走看看