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重建等. 算法主要的思想是在三维离散数据场中通过线性插值来逼近等 ...
随机推荐
- 获取崩溃时的调用栈和生成dump文件,然后自动重启
首先要说明的是: linux 下 比较方便可以得到 崩溃时的调用栈,win下 比较难办 1. linux 获取调用栈 代码奉上: #include <execinfo.h> //在头 ...
- Anisotropic Specular Shader
[Anisotropic Specular] Anisotropic Specular(各向异性反射)模拟表面凹槽的方向性.就像CD表面一样.CD的表面凹槽是有方向的. BlinnPhong中Spec ...
- Spark之 SparkSql整合hive
整合: 1,需要将hive-site.xml文件拷贝到Spark的conf目录下,这样就可以通过这个配置文件找到Hive的元数据以及数据存放位置. 2,如果Hive的元数据存放在Mysql中,我们还需 ...
- android-tip-关于SurfaceView的使用
1. SurfaceView的创建和销毁 当SurfaceView隐藏时,SurfaceView被销毁,此时会调用SurfaceHolder.Callback.surfaceDestroyed ...
- Mosquitto 单向SSL配置
Mosquitto 单向SSL配置 摘自:https://blog.csdn.net/a_bcd_123/article/details/70167833 2017年04月14日 06:56:06 s ...
- 实践作业3:白盒测试----junit的难点DAY11.
本次白盒测试 需要独立完成整个项目和工具的配置安装运行操作,并编写.运行测试脚本,并完成实验的一些小细节等等. 首先,导入Junit测试框架所需的Jar包 然后编写测试脚本,为.java运行程序,见打 ...
- 为啥final类型的map或者arraylist可以修改数据 而final类型的String变量不可以修改数据呢
比如 final Map map =new HashMap(); 可以往map里put数据final List list =new ArrayList(); 可以往list里 ...
- MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error
今天购物车突然不能添加了,发现redis报错了,重启了一下好了,一会又报错了. 错误信息: MISCONF Redis is configured to save RDB snapshots, but ...
- iBeacon的第一篇(基于Swift实现)
低功耗蓝牙技术现在几乎是只能手机的标配.随着这一技术的发展,苹果在2013年WWDC大会上,苹果推出iBeacon技术.该技术允许开发人员开发能够使用iBeacon硬件传感器的iOS应用程序,来为相应 ...
- struts整合dropzone.js上传图片遇到的点问题
问:struts后台无法获取文件对象和文件名称? 答:1. 到dropzone.js搜索"return xhr.send(formData);" 2. 在它前面有个这么句代码: f ...