循环
2016-05-29 21:34
375 查看
N - N
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
先用自己最瘦脸的方法写出来 然后再去考虑其他的方法改进 否则想多了思路就会乱掉 得不偿失
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int a,*b[100],*p,c,i,j,k,l,t,cnt,max,n,y,d,s;
char str[110];
while(scanf("%d",&n)!=EOF)
{
s=1;
for(i=1;i<=n;i++)
{
scanf("%d",&a);
if(s>a)
{
max=s;
}
else
{
max=a;
}
for(j=max;;j++)
{
if(j%s==0&&j%a==0)
{
s=j;
break;
}
}
}
printf("%d\n",s);
}
return 0;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6
3 2 5 7
Sample Output
12
70
先用自己最瘦脸的方法写出来 然后再去考虑其他的方法改进 否则想多了思路就会乱掉 得不偿失
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int a,*b[100],*p,c,i,j,k,l,t,cnt,max,n,y,d,s;
char str[110];
while(scanf("%d",&n)!=EOF)
{
s=1;
for(i=1;i<=n;i++)
{
scanf("%d",&a);
if(s>a)
{
max=s;
}
else
{
max=a;
}
for(j=max;;j++)
{
if(j%s==0&&j%a==0)
{
s=j;
break;
}
}
}
printf("%d\n",s);
}
return 0;
}
相关文章推荐
- 天梯匹配系统 - 简单实现
- [平衡树动态维护凸包] BZOJ 2300 [HAOI2011]防线修建
- hdu 4607(树的直径)
- 学习进度条13
- C语言编程经验总结
- 关于在配置hexo中遇到的问题
- 看了下微软更新的Win10系统,特地开了个UWP目录,与大家交流UWP开发
- 寻找数组中的众数
- E: Sub-process /usr/bin/dpkg returned an error code (1) 出错解决方案
- 1008 Problem H
- 易生活(三)-APP—ninegridview源码阅读
- 模块
- 根文件系统制作
- [2015-11-04 21:42:47 - UIWidgetTest] res\drawable-hdpi-v4\Lighthouse.png: Invalid file name: must co
- bzoj1014火星人
- [主席树优化建图 最小割] BZOJ 3218 a + b Problem
- POJ 2376 Cleaning Shifts (贪心,区间覆盖)
- 项目第三周总结
- 模块
- 模块