NEFU 983 vd折纸

来源:互联网 发布:修图软件app 编辑:程序博客网 时间:2024/05/17 03:17

vd折纸

Num : 5

Time Limit : 1000ms

Memory Limit : 65536K

description

vd折纸VD上高数闲着无聊想要折纸,VD现在想要正方形的纸,但手中只有一张a*b的纸。于是现在需要裁纸。方法如下:先大致折出一条对角线,然后裁去多余的部分。为了节约,多出来的部分他又会做相同的步骤裁出更多的小正方形。
现在VD想要知道,总共能裁出多少个小正方形。

input

多组输入输出,第一行由两个整数a,b组成(1<=b<a<=10^12)。

output

对于每组数据输出一行,VD能裁出多少个正方形。

sample_input

2 110 71000000000000 1

sample_output

261000000000000

hint

source


数据大时减法太慢,用除法处理。

AC  code:

#include<iostream>#include<cstdio>using namespace std;int main(){    long long a,b;    while(cin>>a>>b)    {        long long ans=0;        while(a!=b&&a!=0&&b!=0)        {            if(a>b)            {                ans+=a/b;             //除法,取模,减少运算次数                a=a%b;                             }            else            {                ans+=b/a;                b=b%a;            }        }        cout<<ans<<endl;    }    return 0;}





T E L   code:

#include<iostream>#include<cstdio>using namespace std;int main(){long long a,b;while(cin>>a>>b){long long ans=0;while(a%b!=0){if(a>b){a=a-b;}elseb=b-a;ans++;}if(a!=b)if(a>b)ans+=a/b;elseans+=b/a;cout<<ans<<endl;}return 0;}


0 0