2018年5月12日 星期六

itsa62 5Frog Jumping

#include<iostream>
using namespace std;

int main()
{
int t,X,N,L,a,b,count,ans;
int arr[60000] = {0};
cin >> t;
for (int i = 0;i < t; i++)
{
cin >> X;
cin >> N;
for (int j = 0;j < N; j++)
{
cin >> a >> b;
for (int x = a + 1;x <= b - 1; x++)
arr[x] = 1;
}
for (L = 1;L <= X; L++)
{
ans = 0;
count = L;
for (int y = count;y <= X*2; y += count)
{
if (arr[y] == 1)
{
ans = 1;
break;
}
else if (ans == 0 && y >= X && y <= X*2)
{
cout << L << endl;
break;
}
}
if (ans == 0)
break;
}
}
return 0;
}

沒有留言:

張貼留言