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\n");
        else printf("No\n");
    }
    return 0;
}

  

posted @ 2015-12-30 22:05  20143605  阅读(257)  评论(0编辑  收藏  举报