The following program is my ACcepted code for NTHU-7492 .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7492 的AC code!
//This program is for NTHU 7492 - 最後的紅線!(II)
//題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7492
#include<stdio.h>
#include<stdlib.h>
using namespace std;
long long int GCD(long long int a, long long int b)
{
if(a < b)
return GCD(b, a);
if(b == 0)
return a;
return GCD(b, a%b);
}
int main()
{
long long int x, y;
//一開始用 %I64d 會WA, 改成 %lld 就AC了
while(scanf("%lld %lld", &x, &y) != EOF)
{
long long int tmp = GCD(x, y);
printf("%lld\n", x * (y / tmp));
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃NTHU 7492 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
//題目來源 Problem link: http://acm.cs.nthu.edu.tw/problem.php?pid=7492
#include<stdio.h>
#include<stdlib.h>
using namespace std;
long long int GCD(long long int a, long long int b)
{
if(a < b)
return GCD(b, a);
if(b == 0)
return a;
return GCD(b, a%b);
}
int main()
{
long long int x, y;
//一開始用 %I64d 會WA, 改成 %lld 就AC了
while(scanf("%lld %lld", &x, &y) != EOF)
{
long long int tmp = GCD(x, y);
printf("%lld\n", x * (y / tmp));
}
return 0;
}
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!