Codeforce - 267 - A. Subtractions
来源:互联网 发布:普通话测试软件 编辑:程序博客网 时间:2024/06/01 08:58
A. Subtractions
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You’ve got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You’ve got some number of pairs (ai, bi). How many operations will be performed for each of them?
Input
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Output
Print the sought number of operations for each pair on a single line.
Examples
input
2
4 17
7 987654321
output
8
141093479
题意:大数减小数,直到其中一个数为 0 为止。求步数。
AC代码:
#include <iostream>using namespace std;int main(){ int n; cin>>n; while (n--) { int a,b; cin>>a>>b; int ans=0; int mn=min(a,b),mx=max(a,b); int ansmn=mn,ansmx=mx; do { ans+=(mx/mn); mx%=mn; ansmn=min(mx,mn);ansmx=max(mx,mn); mn=ansmn;mx=ansmx; }while (mx && mn); cout<<ans<<endl; }}
- Codeforce - 267 - A. Subtractions
- codeforces 267A A. Subtractions(辗转相除)
- Codeforce A
- Codeforce # A Plug-in
- codeforce 2A Winner
- Contest on codeforce A
- codeforce 11 04 A
- codeforce小水题--A. Presents
- Codeforce #145A Cinema
- codeforce日记 371A
- CodeForce 393A Nineteen
- codeforce 402A - Nuts
- Codeforce A. Milking cows
- codeforce 427A
- codeforce 433A
- codeforce 6A
- codeforce 7A
- codeforce 9A
- 【PAT】1043. Is It a Binary Search Tree
- Java垃圾回收机制
- Mybatis与Spring结合
- hjr教程-JSP(五):SpringMVC进阶
- web前端12
- Codeforce - 267 - A. Subtractions
- 数据库操作
- EL表达式简介
- UVa 489 Hangman Judge 【模拟】【练习函数的用法】
- 先挖几个坑
- web前端13
- mutableArrayValueForKey:@"subModels"
- C++继承(一)
- HNOI 2008 GT考试