编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#81607 #106. zxh的同值猜想 Accepted 100 42 ms 384 K C / 1.3 K Ypy 2022-12-07 0:11:08
显示原始代码
#include <stdio.h>
#include <string.h>
#include <math.h>
#define Max 100  //输入数字限定最大值,视情况而更改
int gy(int a, int b) {
    if (a == b) {
        return a;
    } else if (a > b) {
        return gy(a - b, b);
    } else {
        return gy(a, b - a);
    }
}
int main() {
    char x[Max], y[Max];
    scanf("%s %s", x, y);
    int l1 = (int)strlen(x), l2 = (int)strlen(y), x1 = 0, y1 = 0;
    //对两数字进行数乘操作,和为z数组;
    int a[Max] = { 0 }, b[Max] = { 0 };
    for (int i = 0, n = l1 - 1; i < l1; i++, n--) {
        a[i] = x[n] - '0';
        x1 += a[i] * (int)pow(10, i);
    }
    for (int i = 0, n = l2 - 1; i < l2; i++, n--) {
        b[i] = y[n] - '0';
        y1 += b[i] * (int)pow(10, i);
    }  //将数字按位置从0到最大位保存到数组里
    int pro[Max * Max] = { 0 };
    for (int i = 0; i < l1; i++) {
        for (int j = 0; j < l2; j++) pro[i + j] += a[i] * b[j];
    }  //对应数相乘,不考虑进位,保持对应列数值。
    for (int i = 0; i < l1 + l2; i++) {
        if (pro[i] > 9) {
            pro[i + 1] += (pro[i] / 10);
            pro[i] %= 10;
        }
    }  //进位
    int begain = l1 + l2 - 1;
    for (; pro[begain] == 0; begain--) {
    }
    //乘法完成,且最高位储存在begain处;
    //完成除法运算。
    int z = gy(x1, y1);
    for (int i = begain; i >= 0; i--) {
        if (i > 0) {
            pro[i - 1] += (pro[i] % z * 10);
        }
        pro[i] /= z;
    }
    for (; pro[begain] == 0; begain--) {
    }
    printf("%d ", z);
    for (int i = begain; i >= 0; i--) {
        printf("%d", pro[i]);
    }
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:2 ms
内存:328 KiB

输入文件(1.in

7 5

答案文件(1.out

1 35

用户输出

1 35

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:2 ms
内存:272 KiB

输入文件(2.in

67 26

答案文件(2.out

1 1742

用户输出

1 1742

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:2 ms
内存:196 KiB

输入文件(3.in

52 15

答案文件(3.out

1 780

用户输出

1 780

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:2 ms
内存:384 KiB

输入文件(4.in

96 77

答案文件(4.out

1 7392

用户输出

1 7392

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:2 ms
内存:384 KiB

输入文件(5.in

8 12

答案文件(5.out

4 24

用户输出

4 24

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:2 ms
内存:256 KiB

输入文件(6.in

87 33

答案文件(6.out

3 957

用户输出

3 957

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:2 ms
内存:308 KiB

输入文件(7.in

88 28

答案文件(7.out

4 616

用户输出

4 616

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:2 ms
内存:256 KiB

输入文件(8.in

76 54

答案文件(8.out

2 2052

用户输出

2 2052

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:2 ms
内存:256 KiB

输入文件(9.in

6 75

答案文件(9.out

3 150

用户输出

3 150

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:2 ms
内存:324 KiB

输入文件(10.in

53 53

答案文件(10.out

53 53

用户输出

53 53

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:3 ms
内存:384 KiB

输入文件(11.in

15734 71136

答案文件(11.out

2 559626912

用户输出

2 559626912

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:2 ms
内存:260 KiB

输入文件(12.in

70872 21669

答案文件(12.out

3 511908456

用户输出

3 511908456

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:2 ms
内存:256 KiB

输入文件(13.in

99784 94882

答案文件(13.out

2 4733852744

用户输出

2 4733852744

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:3 ms
内存:304 KiB

输入文件(14.in

95038 97852

答案文件(14.out

2 4649829188

用户输出

2 4649829188

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:2 ms
内存:256 KiB

输入文件(15.in

94814 98836

答案文件(15.out

2 4685518252

用户输出

2 4685518252

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:3 ms
内存:248 KiB

输入文件(16.in

95890 93558

答案文件(16.out

2 4485638310

用户输出

2 4485638310

系统信息

Exited with return code 0
测试点 #17
Accepted
得分:100
用时:2 ms
内存:320 KiB

输入文件(17.in

528340267 186251667

答案文件(17.out

7 14057750781710727

用户输出

7 14057750781710727

系统信息

Exited with return code 0
测试点 #18
Accepted
得分:100
用时:1 ms
内存:232 KiB

输入文件(18.in

367608218 157640544

答案文件(18.out

2 28974979732195296

用户输出

2 28974979732195296

系统信息

Exited with return code 0
测试点 #19
Accepted
得分:100
用时:2 ms
内存:272 KiB

输入文件(19.in

324952863 177819387

答案文件(19.out

3 19260972967518327

用户输出

3 19260972967518327

系统信息

Exited with return code 0
测试点 #20
Accepted
得分:100
用时:2 ms
内存:252 KiB

输入文件(20.in

541339672 595238966

答案文件(20.out

2 161113233308029576

用户输出

2 161113233308029576

系统信息

Exited with return code 0