九度oj 最大公约数(gcd)(这缩写!!!) 最小公倍数(lcm) 1056,1438,1439

1056题目:

http://ac.jobdu.com/problem.php?pid=1056

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1:0
 
using namespace std;
int main(){
  int a,b;
  int t;
  while(cin>>a>>b){
     while(1){
       t=a%b;
       if(t==0){
          t=b;
          break;
       }
       a=b;
       b=t;
     }
     cout<<t<<endl;
  }
}
 
/**************************************************************
    Problem: 1056
    User: zhouyudut
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1520 kb
****************************************************************/
1438题目:

http://ac.jobdu.com/problem.php?pid=1438

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1:0
 
using namespace std;
int main(){
  int a,b;
  int t;
  while(cin>>a>>b){
      int tempa=a;
      int tempb=b;
     while(1){
       t=a%b;
       if(t==0){
          t=b;
          break;
       }
       a=b;
       b=t;
     }
     cout<<(tempa*tempb)/t<<endl;
  }
}
 
/**************************************************************
    Problem: 1438
    User: zhouyudut
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/
1439题目:

http://ac.jobdu.com/problem.php?pid=1439

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1:0
 
using namespace std;
unsigned long long int lcm(unsigned long long int  a,unsigned long long int b){
  if(b==0)
    return a;
  long long int t;
  long long int tempa=a;
  long long int tempb=b;
  while(1){
    t=tempa%tempb;
    if(t==0)
    {
        t=tempb;
        break;
    }
    tempa=tempb;
    tempb=t;
  }
  return a*b/t;
}
int main(){
  unsigned long long  int a,b;
  unsigned long long int num,count;
  cin>>num;
  for(unsigned long long int i=0;i<num;i++){
     cin>>count;
     a=1;
     for(unsigned long long int j=0;j<count;j++){
        cin>>b;
        a=lcm(a,b);
     }
     cout<<a<<endl;
  }
}
 
/**************************************************************
    Problem: 1439
    User: zhouyudut
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/
对于这题,注意数的范围,这玩意很坑的






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值