| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6127 人关注过本帖
标题:[讨论]第二期题目,大家做做.
只看楼主 加入收藏
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
结帖率:50%
收藏
 问题点数:0 回复次数:75 
[讨论]第二期题目,大家做做.

Least Common Multiple

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 2373 Accepted Submit: 906

--------------------------------------------------------------------------------
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

求最小公倍数.

搜索更多相关主题的帖子: positive multiple example numbers Memory 
2006-11-19 16:01
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

Digital Roots

--------------------------------------------------------------------------------

Time limit: 1 Seconds Memory limit: 32768K
Total Submit: 8841 Accepted Submit: 1989

--------------------------------------------------------------------------------

Background

The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.


Input

The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.


Output

For each integer in the input, output its digital root on a separate line of the output.


Example

Input

24
39
0
Output

6
3
这个题目比较简单,简单说一下:
给定一个数,求它的数根,即每一位的和组成一个新的数,直到所求的和是一个一位数为止.

求数根:例如39
是这样求到的39--->3+9=12--->1+2=3结束.
123456--->1+2+3+4+5+6=16=1+6=7结束.


倚天照海花无数,流水高山心自知。
2006-11-19 16:06
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 

文件名称?
输入输出文件名?

[此贴子已经被作者于2006-11-19 16:10:23编辑过]


My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2006-11-19 16:06
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
这些都没有,只要写个程序.提交后,它自动输入数据测试你的程序的正确性,不需要指定的文件.

倚天照海花无数,流水高山心自知。
2006-11-19 16:13
zxd198778
Rank: 1
等 级:新手上路
帖 子:99
专家分:0
注 册:2006-7-30
收藏
得分:0 

小弟不才
不懂英语,能翻译一下吗
那位高手


我一个不懂世事的人,希望能在这里学到我想学的一些东西。
2006-11-19 16:38
cwande
Rank: 2
等 级:新手上路
威 望:3
帖 子:333
专家分:0
注 册:2006-8-18
收藏
得分:0 
第二题:
[CODE]#include<stdio.h>
#include<string.h>
const int M=10000;
char a[M];
int main()
{
int i,len,sum;
while(gets(a),a[0]!='0')
{
sum=0;
for(i=0,len=strlen(a);i<len;i++)
sum+=a[i]-48;
if(sum>9)sum%=9;
if(sum==0)sum=9;
printf("%d\n",sum);
}
return 0;
}[/CODE]

汗,都懒得写代码了.......... cheat了一个威望,哈.....
2006-11-19 16:41
我不是郭靖
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:494
专家分:6
注 册:2006-10-4
收藏
得分:0 

#include<stdio.h>
#define M 200
#define N 5000
long lcm(long m,long n)
{
long t,m1=m,n1=n;
if(m>n)
{
t=m;
m=n;
n=t;
}
while(n%m!=0)
{
t=n;
n=m;
m=t%m;
}
return m1/m*n1;
}
int main()
{
long i,j,n,a[M][N];
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&a[i][0]);
for(j=1;j<=a[i][0];j++)
scanf("%ld",&a[i][j]);
}
for(i=0;i<n;i++)
{
long temp=1;
for(j=1;j<=a[i][0];j++)
temp=lcm(temp,a[i][j]);
printf("%ld\n",temp);
}
return 0;
}


2006-11-19 16:47
cwande
Rank: 2
等 级:新手上路
威 望:3
帖 子:333
专家分:0
注 册:2006-8-18
收藏
得分:0 

Least Common Multiple:
[CODE]#include<stdio.h>
const int M=1000;
int gcd(long long m,long long n)
{
long long t,r;
if(m>n)
t=m,m=n,n=t;
while(n%m)
{
r=n%m;
n=m;
m=r;
}
return m;
}
int main()
{
long long a[M],temp;
int _,i,n;
scanf("%d",&_);
while(_--)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%lld",&a[i]);
temp=a[1];
for(i=2;i<=n;i++)
temp=temp*a[i]/gcd(temp,a[i]);
printf("%lld\n",temp);
}
return 0;
}[/CODE]


汗,都懒得写代码了.......... cheat了一个威望,哈.....
2006-11-19 16:49
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 

第二题!呵呵!这方法可不是我想出来的!
#include<stdio.h>

int main(void)
{
char str[10];
int num = 0, i;

gets(str);
for(i = 0;i < 2;i ++)
{
num += str[i] - '0';
}
while(num > 10)
{
num = num/10 +num%10;
}
printf("%d\n", num);

return 0;
}


该学习了。。。
2006-11-19 17:03
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
第二题好象在论坛里见过,不太清楚,大家做一下,比较简单.

如果不超过8个人做的话,下次我也懒得再发题目了,觉得没意思.
望大家原谅.

倚天照海花无数,流水高山心自知。
2006-11-19 17:07
快速回复:[讨论]第二期题目,大家做做.
数据加载中...
 
   



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

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