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
2
2 4 6
1 2 3
2 6
1 6
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.
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.
Blocks to Cubes的更多相关文章
- Intel® Threading Building Blocks (Intel® TBB) Developer Guide 中文 Parallelizing Data Flow and Dependence Graphs并行化data flow和依赖图
https://www.threadingbuildingblocks.org/docs/help/index.htm Parallelizing Data Flow and Dependency G ...
- POJ 1052 Plato's Blocks
Plato's Blocks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 734 Accepted: 296 De ...
- Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs
D. Bear and Tower of Cubes 题目连接: http://www.codeforces.com/contest/680/problem/D Description Limak i ...
- codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)
题目链接: D. Bear and Tower of Cubes time limit per test 2 seconds memory limit per test 256 megabytes i ...
- Codeforces Round #295 D. Cubes [贪心 set map]
传送门 D. Cubes time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 开发该选择Blocks还是Delegates
前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中在stablekernel找到了这篇文章,文中作者不仅仅是给出了解决方案,更值得我们深思的是作者独特 ...
- 水泡动画模拟(Marching Cubes)
Marching Cubes算法是三维离散数据场中提取等值面的经典算法,其主要应用于医学领域的可视化场景,例如CT扫描和MRI扫描的3D重建等. 算法主要的思想是在三维离散数据场中通过线性插值来逼近等 ...
随机推荐
- KVM镜像image 转换 调整
qemu-img create -f raw test.raw 8G 创建一个raw格式,大小为8G的镜像. qemu-img info disk1.qcow2 #查看镜像大小及实际占用多少空 ...
- 转 Android:文件下载和写入SD卡学习小结
转自 http://blog.csdn.net/zzp_403184692/article/details/8160739 一.文件下载 Android开发中,有时需要从网上下载一些资源以供用户使 ...
- Android判断Service是否运行
/** * 用来判断服务是否运行. * @param context * @param className 判断的服务名字 * @ret ...
- linux安装wifi驱动,开热点
本次安装的debian系统安装的时候提示wifi硬件需要安装非自由固件才能运行,并告诉本硬件要安装的固件名字叫做iwlwifi-2030-6.ucode.是iwlwifi驱动适配我的wireless硬 ...
- 150. Evaluate Reverse Polish Notation (Stack)
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
- jmeter 读取mysql数据库
业务背景 当我们用jmeter进行压测,或者造数据的时候,我们可能希望每次请求的参数都是随机的.如果从一个文件里读取,很难达到要求.jmeter提供了一套读取数据库的组件,能满足部分要求.但性能不好, ...
- java实现文件的拷贝以及文件的删除
/** * 将文件拷贝到指定目录 * @param oldAddress 文件所在目录(文件的全路径) * @param newAddress 指定目录(包含复制文件的全名称) * @throws E ...
- Kubuntu上截屏的小技巧
Kubuntu上自带了截屏软件ksnapshot,只需要按Print Screen就会自动调起,实际上挺方便的:但是,Print Screen的默认行为是截下整个屏幕,这往往不是我们需要的. 实际上, ...
- Win10 提升系统响应速度
转载百度经验: https://jingyan.baidu.com/article/54b6b9c0e9d61e2d583b4719.html 1.鼠标左键点击开始按钮,然后点击菜单中的设置,进入设置 ...
- Unix进程特性
本篇文章主要总结分享记录一下运维工作中经常打交道的Unix进程.程序是代码的集合,而进程是运行中的程序产生的.那么进程都有那些特性呢?且看下文,部分经典且难懂的地方,使用python代码实现,可以让读 ...