zoukankan      html  css  js  c++  java
  • [luoguP1069] 细胞*(数论)

    传送门

    分解质因数,不说了

    这题坑了我2个多小时

    教训

    不熟悉位运算的优先级一定要加括号!!!!

    #include <cstdio>
    #include <iostream>
    #define N 1000001
    #define LL long long
    #define max(x, y) ((x) > (y) ? (x) : (y))
    #define min(x, y) ((x) < (y) ? (x) : (y))
    
    int n, m1, m2, m, sum, ans = 1e9, tot, t = 1, p;
    int b[N], c[N];
    bool f;
    
    inline int read()
    {
        int x = 0, f = 1;
        char ch = getchar();
        for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
        for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
        return x * f;
    }
    
    inline int gcd(int x, int y)
    {
        return !y ? x : gcd(y, x % y);
    }
    
    int main()
    {
        int i, j, a, x;
        n = read();
        m1 = read();
        m2 = read();
        if(m1 == 1)
        {
        	puts("0");
        	return 0;
        }
        x = m1;
        for(j = 2; j <= m1; j++)
        {
    	    while(!(x % j)) c[t] = j, b[t]++, x /= j;
            b[t] *= m2;
    		if(b[t]) t++;
    	}
    	t--;
        for(i = 1; i <= n; i++)
        {
            sum = f = 0;
            p = 1;
            x = a = read();
            if(gcd(m1, a) == 1) continue;
            for(j = 2; j <= a; j++)
            {
                tot = 0;
                while(!(x % j)) tot++, x /= j;
                if(tot && c[p] == j) sum = max(sum, b[p] / tot + (b[p] % tot != 0)), p++;
                if(c[p] < j) break;
            }
            if(p > t) ans = min(ans, sum);
        }
        printf("%d
    ", ans == 1e9 ? -1 : ans);
        return 0;
    } 
    

      

  • 相关阅读:
    better-scroll 介绍
    promise 异步编程
    vue网址路由的实时检测
    浏览器本地存储的使用
    获取元素的位置
    如何设置动画的运动效果
    实现对称加密及非对称公钥加密
    Centos 7系统启动修复
    Centos 7服务启动文件
    内核编译-4.12
  • 原文地址:https://www.cnblogs.com/zhenghaotian/p/7056002.html
Copyright © 2011-2022 走看看