题目描述:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it’s not a NP problem.
输入描述:
The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).
输出描述:
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
输入:
19 29
3 6
输出:
2
3
题意:
记下这些整数的所有的整数除数(除了1之外)并从这些整数除数中找出出现次数最多的那个整数除数。若出现次数最多的那个数有多个,则任意输出一个即可。
题解:
左右相等的话,直接输出自身。如果右端点大于2,肯定是2最多。
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
int l,r;
while(scanf("%d%d",&l,&r)!=EOF){
if(l == r) printf("%d\n",l);
else if(r > 2) printf("2\n");
else printf("1\n");
}
return 0;
}