zoukankan      html  css  js  c++  java
  • sicily 1623. Sixth Grade Math

    Description
    In sixth grade, students are presented with different ways to calculate the Least Common Multiple (LCM) and the Greatest Common Factor (GCF) of two integers. The LCM of two integers a and b is the smallest positive integer that is a multiple of both a and b . The GCF of two non-zero integers a and b is the largest positive integer that divides both a and b without remainder.
    Input
    The first line of input contains a single integer N , (1≤N≤1000) which is the number of data sets that follow. Each data set consists of a single line of input containing two positive integers, a and b , (1≤a, b≤1000) separated by a space.
    Output
    For each data set, you should generate one line of output with the following values: The data set number as a decimal integer (start counting at one), a space, the LCM, a space, and the GCF.

    水题,GCF其实就是GCD,最大公约数,LCM最小公倍数有一个公式lcm(a,b) = a*b/gcd(a,b)……很水

    View Code
     1 #include<stdio.h>
     2 int gcf( int a, int b )
     3 {
     4     if( a == 0)
     5         return b;
     6     if ( b == 0 )
     7         return a;
     8     return gcf( b, a % b );
     9 
    10 }
    11 
    12 int lcm( int a, int b )
    13 {
    14     return a * b / gcf(a, b);
    15 }
    16 int main()
    17 {
    18     int n, i, a, b;
    19     
    20     scanf("%d", &n);
    21     for ( i = 1; i <= n; i++ )
    22     {
    23         scanf("%d %d", &a, &b);
    24         printf("%d %d %d\n", i, lcm(a, b), gcf(a, b));
    25     }
    26     
    27     return 0;
    28 }
  • 相关阅读:
    BZOJ1106[POI2007]立方体大作战tet
    BZOJ4407 于神之怒加强版
    BZOJ1103: [POI2007]大都市meg
    BZOJ3170: [Tjoi2013]松鼠聚会
    Luogu 2912 [USACO08OCT]牧场散步Pasture Walking
    BZOJ1251 序列终结者- splay
    BZOJ1699: [Usaco2007 Jan]Balanced Lineup排队
    BZOJ 1005[HNOI2008]明明的烦恼
    二叉树
    [CODEVS1130]数字反转
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2882376.html
Copyright © 2011-2022 走看看