| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:杭电1019
只看楼主 加入收藏
Buger
Rank: 1
等 级:新手上路
帖 子:60
专家分:7
注 册:2013-3-20
结帖率:84.62%
收藏
已结贴  问题点数:20 回复次数:2 
杭电1019
程序代码:
Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.
Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
105
10296
我的代码:
#include <stdio.h>

int main() {
    int a, b, temp, n, s[1000], t, i, m, j;
    scanf("%d", &m);
    while(m--) {
        scanf("%d", &n);
        for(i = 0; i < n; i++) scanf("%d", &s[i]);
        for(i = 0; i < n - 1; i++)
            for(j = 0; j < n - 1 - i; j ++)
                if(s[j] > s[j + 1]) {
                    t = s[j];
                    s[j] = s[j + 1];
                    s[j + 1] = t;
                }
        if(s[n - 2] < s[n - 1]) {
            temp = s[n - 1];
            s[n - 1] = s[n - 2];
            s[n - 2] = temp;
        }
        a = s[n - 2]; b = s[n - 1];
        while(b != 0) {
            temp = a % b;
            a = b;
            b = temp;
        }
        printf("%d\n", s[n - 1] / a * s[n - 2]);
    }
    return 0;
}
地址:
http://acm.hdu.
总是错误..怎么回事?

 
搜索更多相关主题的帖子: set positive multiple contain 
2013-04-20 00:09
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:5 
5 2 3 5 7 9


[fly]存在即是合理[/fly]
2013-04-20 15:04
Susake
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:女儿国的隔壁
等 级:贵宾
威 望:23
帖 子:2288
专家分:6481
注 册:2012-12-14
收藏
得分:15 
程序代码:
#include <stdio.h>
int gcd(int *a, int *b) {
    int c= *a, d = *b, n = *a, m = *b, t;
    if(n < m) {t = n; n = m; m = t;}
    while(m != 0) {
        t = n % m;
        n = m;
        m = t;
    }
    return c / n * d;
}
int main() {
    int a[1000], n, m, i, j, g;
    scanf("%d", &n);
    while(n--) {
        scanf("%d", &m);
        if(m == 1) {
            scanf("%d", &g);
            printf("%d\n", g);
        }
        else {
            for(i = 0; i < m; i++) scanf("%d", &a[i]);
            for(i = 0, j = i + 1; j < m; j++) {
                a[i] = gcd(&a[i], &a[j]);
            }
            printf("%d\n", a[i]);
        }
    }
    return 0;
}

仰望星空...........不忘初心!
2013-04-20 15:20
快速回复:杭电1019
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021402 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved