1 条题解
-
0
C :
#include<stdio.h> int main() { int x,y,r; while(scanf("%d,%d",&x,&y)!=EOF) { r=x%y; while(x%y!=0) { x=y; y=r; r=x%y; } printf("%d\n",y); } }C++ :
#include<stdio.h> #include<iostream> using namespace std; int main() { int r,a,b; scanf("%d,%d",&a,&b); if(a>=b) { r=a%b; if(r==0) { printf("%d\n",b); } while(r!=0) { a=b; b=r; r=a%b; if(r==0) { printf("%d\n",b); } } } else if(a<=b) { r=b%a; if(r==0) { printf("%d\n",a); } while(r!=0) { b=a; a=r; r=b%a; if(r==0) { printf("%d\n",a); } } } return 0; }Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] str = sc.nextLine().split(","); int a = Integer.parseInt(str[0]); int b = Integer.parseInt(str[1]); int Max = Math.max(a,b); int Min = Math.min(a,b); while (Max % Min != 0){ int temp = Max % Min; Max = Min; Min = temp; } System.out.println(Min); } }Python :
# coding=utf-8 #python2 a,b = map(int,raw_input().split(',')) if b > a: c = a a = b b = c i = b while a%i!=0 or b%i!=0: i -= 1 print(i)C# :
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { internal class Program { static void Main() { string[] strings = Console.ReadLine().Split(','); int a = Convert.ToInt32(strings[0]); int b = Convert.ToInt32(strings[1]); int c = 0; int ans = 0; if (b > a) { c=b; b=a; a=c; } for (int i = b; i >=1; --i) { if (a % i == 0 && b % i == 0) { ans = i; break; } } Console.WriteLine(ans); Console.ReadKey(); } } }
- 1
信息
- ID
- 42
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者