zoukankan      html  css  js  c++  java
  • hrbust 1328 相等的最小公倍数(数论)

    Description

    定义An为1,2,…,n的最小公倍数,例如,A1 = 1,A2 = 2,A3 = 6,A4 = 12,A5 = 60,A6 = 60。

    请你判断对于给出的任意整数n,An是否等于An – 1

    Input

    本题有多组测试数据,输入的第一行是一个整数T代表着测试数据的数量,接下来是T组测试数据。

    对于每组测试数据:

    第1行 包含一个整数n (2 ≤ n ≤ 106)。

    Output

    对于每组测试数据:

    第1行 如果An等于An-1则输出YES否则输出NO。

    Sample Input

    1

    6

    Sample Output

    YES

    /***********************

    突然认识到基础不扎实,练习一下打基础,

    数论欧几里得算法的简单应用 

    题意不说了,很简单,

    对于 n ,n为素数时肯定是NO,

    对于其他的 n 来说:

    如果 n 有一对互质的因子则输出YES,否则输出 NO 。

    **********************/

    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int gcd(int a,int b)//  求最大公约数
    {
        if(a == 0)
            return b;
        int c;
        while(b)
        {
            c = b;
            b = a%b;
            a = c;
        }
        return a;
    }
    int prime(int n)//  判断素数
    {
        int i;
        for(i = 2;i*i<=n;i++)
            if(n%i==0)
                return 0;
        return 1;
    }
    int main()
    {
        int i,t,n,leaf;
        scanf("%d",&t);
        while(t--)
        {
            leaf = 1;
            scanf("%d",&n);
            if(prime(n))//  n是素数是直接输出NO
            {
                printf("NO
    ");
                continue;
            }
            for(i = 2;i*i<=n;i++)
            {
                if(n%i==0)
                {
                    int p = n/i;
                    if(gcd(p,i)==1)
                    {
                        leaf = 0;
                        break;
                    }
                }
            }
            if(leaf == 1)
                printf("NO
    ");
            else
                printf("YES
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    今天面试一些程序员(新,老)手的体会
    UVA 10635 Prince and Princess
    poj 2240 Arbitrage
    poj 2253 Frogger
    poj 2485 Highways
    UVA 11258 String Partition
    UVA 11151 Longest Palindrome
    poj 1125 Stockbroker Grapevine
    poj 1789 Truck History
    poj 3259 Wormholes
  • 原文地址:https://www.cnblogs.com/gray1566/p/3704292.html
Copyright © 2011-2022 走看看