zoukankan      html  css  js  c++  java
  • Blocks to Cubes

    Bholu the Pandit on this New Year wanted to divide his Cuboidal Packaging block into cubes. But he loves uniformity so he asks you to divide it such a way that all the cubes are of same size and volume of individual cube is as large as possible.

    Note: He will utilize whole volume i.e volume of cuboid before dividing is same as sum of volume of all the cubes.

    Input
    The first input line contains an integer T, the number of testcases. Each testcase consist of single line which consist of 3 space separated integers a, b & c representing length, breadth and height of the Cuboidal block.

    Output
    For each testcase you need to output 2 space separated integers, the length of side of the cube and the number of cubes which could be formed out of this cuboidal packaging block. As the number of cubes which could be made could be a large number so just output the answer modulus 109+7 (1000000007).

    Constraints
    1 ≤ T ≤ 1000
    1 ≤ a,b,c ≤ 109

    SAMPLE INPUT
     
     
    2
    2 4 6
    1 2 3
    SAMPLE OUTPUT
     
     
    2 6
    1 6
    
     
    Explanation

    In the 1st testcase a=2, b=4 & c=6. So length of the side of the cube would be 2 and the number of cubes which would be formed would be 6. In the 2nd testcase a=1, b=2 & c=3. So length of the side of the cube would be 1 and the number of cubes which would be formed would be 6.

    Time Limit:1.0 sec(s) for each input file.
    Memory Limit:256 MB
    Source Limit:1024 KB
    Marking Scheme:Marks are awarded when all the testcases pass.
    Allowed Languages:Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), TypeScript, Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

    Approach # 1: 

    /*
    // Sample code to perform I/O:
    
    #include <iostream>
    
    using namespace std;
    
    int main() {
    	int num;
    	cin >> num;										// Reading input from STDIN
    	cout << "Input number is " << num << endl;		// Writing output to STDOUT
    }
    
    // Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
    */
    
    // Write your code here
    #include<iostream>
    #include<algorithm>
    const int mod = 1e9 + 7;
    
    using namespace std;
    
    long long gcd(long long x, long long y) {
        if (y == 0)
            return x;
        else return gcd(y, x%y);
    }
    
    int main() {
        int n;
        long long l, w, h;
        long long ans;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> l >> w >> h;
            long long c = gcd(gcd(l, w), h);
            l /= c;
            w /= c;
            h /= c;
            ans = (((l * w) % mod) * h) % mod;
            cout << c << ' ' << ans << endl;
        }
        
        return 0;
    }
    

      

    Analysis:

    From this problem I learned how to deal with the three numbers problem. And we shuold use long long.

    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    ssh 私匙登录, 文件rswrst权限
    从内存使用的角度来理解.Net底层架构
    (转)C#为什么要使用Invoke,它和BeginInvoke有什么区别
    如何通过微信自定义菜单跳转到自己的网站
    (转)HubbleDotNet+Mongodb 构建高性能搜索引擎--概述
    (转)HubbleDotNet 和 Lucene.net 性能对比测试
    C#异步提示和技巧
    关于System.Windows.Forms.DateTimePicker的一个Bug
    关于frameset中指定区域回退的实现
    java.lang.NoClassDefFoundError Adding a jar to an RCP application
  • 原文地址:https://www.cnblogs.com/h-hkai/p/10349357.html
Copyright © 2011-2022 走看看