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
求最小公倍数.
----------------解决方案--------------------------------------------------------
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:10:23编辑过]
----------------解决方案--------------------------------------------------------
这些都没有,只要写个程序.提交后,它自动输入数据测试你的程序的正确性,不需要指定的文件.
----------------解决方案--------------------------------------------------------
小弟不才
不懂英语,能翻译一下吗
那位高手
----------------解决方案--------------------------------------------------------
第二题:
[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]
----------------解决方案--------------------------------------------------------
#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;
}
----------------解决方案--------------------------------------------------------
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]
----------------解决方案--------------------------------------------------------
第二题!呵呵!这方法可不是我想出来的!
#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;
}
----------------解决方案--------------------------------------------------------
第二题好象在论坛里见过,不太清楚,大家做一下,比较简单.
如果不超过8个人做的话,下次我也懒得再发题目了,觉得没意思.
望大家原谅.
----------------解决方案--------------------------------------------------------