zoukankan      html  css  js  c++  java
  • CodeForces

    这道题确实是自己太蠢

    每个数通过双倍或者三倍 能否达到同一个数

    当时一直想用LCM/a[i]后来除以2 除以3看最后是否为1 

    然后一直WA On test49

    当然知道是数据爆了 然后就卡住了

    想想如果这n个数能够乘2 乘3 得到同一个数说明 这些数的约数 只在2 和 3的数量上不同 其他约数都应该是相同的

    那么 就按除法 每个数 除以2 除以3 看剩下的约数是否相同 即可

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string>
     4 #include <string.h>
     5 #include <map>
     6 #include <fstream>
     7 #include <set>
     8 #define READ() freopen("in.txt", "r", stdin);
     9 using namespace std;
    10 
    11 
    12 long long gcd(long long a, long long b)
    13 {
    14     if (b == 0) return a;
    15     else return gcd(b, a%b);
    16 }
    17 
    18 long long a[100007];
    19 int main()
    20 {
    21     READ()
    22     int n;
    23     set<int> s;
    24     long long LCM, old_LCM, time;
    25     scanf("%d", &n);
    26     for (int i = 0; i < n; i++)
    27     {
    28         scanf("%lld", &a[i]);
    29     }//求得最小公倍数
    30     for (int i = 0; i < n; i++) //判断是否成功
    31     {
    32         while (!(a[i] % 2)) a[i] /= 2;
    33         while (!(a[i] % 3)) a[i] /= 3;
    34         s.insert(a[i]);
    35     }
    36     if (s.size() == 1 ) printf("Yes
    ");
    37     else printf("No
    ");
    38     return 0;
    39 }
  • 相关阅读:
    告别单身淘宝小店
    微信机器人 细腻化
    # 导入模块 from wxpy import * # 初始化机器人,扫码登陆 bot = Bot()
    减小文件大小 减少 帧
    无有效图视频
    生成一张白色图片的算法--逻辑
    加logo
    字幕 3系数
    音频分析 字幕同步
    尊重百度的api语音合成规则
  • 原文地址:https://www.cnblogs.com/oscar-cnblogs/p/6435312.html
Copyright © 2011-2022 走看看