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