杭电OJ | 1108 2138 2504 最小公倍数 素数

1108 最小公倍数

Input      输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.

Output   对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。

Sample Input

10 14

Sample Output

70

#include<stdio.h>
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		printf("%d\n",n*m/gcd(n,m));
	}
	return 0;
}
int gcd(int a, int b){
	if(a<b){
		int temp = a;
		a = b;
		b = temp;
	}
	a = a%b;
	if(a%b==0){
		return b;
	}
	else{
		return gcd(a,b);
	}
}

2138 How many prime numbers

Input    There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.

Output   For each case, print the number of prime numbers you have found out.

Sample Input

3 2 3 4

Sample Output

 

#include<stdio.h>
#include<math.h>
int main()
{
	int inputnum;
	while(scanf("%d",&inputnum)!=EOF){
		int count = 0;
		for(; inputnum!=0; inputnum--){
			int num;
			scanf("%d",&num);
			if(isprime(num)==1){
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}
int isprime(int a){
	int i;
	for(i=2; i<=sqrt(a); i++){
		if(a%i==0){
			return 0;
		}
	}
	return 1;
}

2504 又见GCD

Problem Description  有三个正整数a,b,c(0<a,b,c<10^6),其中c不等于b。若a和c的最大公约数为b,现已知a和b,求最小的c。

Input       第一行输入一个n,表示有n组测试数据,接下来的n行,每行输入两个正整数a,b。

Output    输出对应的c,每组测试数据占一行。

Sample Input

2

6 2

12 4

Sample Output

4 8

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值