Объяснение:
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N, A, B;
cin >> N;
vector < vector <int>> IO;
int lastDay = 0;
for (int i = 0; i < N; i++) {
cin >> A >> B;
IO.push_back(vector<int>());
IO[i].push_back(A);
IO[i].push_back(B);
IO[i].push_back(i);
}
sort(IO.begin(), IO.end());
for (int i = 0; i < N; i++)
{
if (lastDay >= IO[i][1]) {
IO[i][0] = -1;
IO[i][1] = -1;
}
else {
if (lastDay < IO[i][0]) {
lastDay = IO[i][1];
}
else if (lastDay >= IO[i][0]) {
IO[i][0] = lastDay+1;
lastDay = IO[i][1];
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (IO[j][2] == i) {
cout << IO[j][0] << " " << IO[j][1] << endl;
break;
}
}
}
return 0;
}
public class prosto {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println("Программа определения простого числа");
System.out.println("");
int n, s=0, i=2;
System.out.println("Введите натуральное число (>0)>");
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
if (n==1) System.out.println(n+" - число не просто и не составное");
else
{
while (i*i <= n) {
if (n % i == 0) ++s;
++i;
}
if (s == 0) System.out.println(n+" - простое число!");
else System.out.println(n + " - составное число!");
}
System.out.println(i-2+" - итераций");
System.out.print("Нажмите ENTER для выхода...");
System.in.read(); //задержка (аналог system("PAUSE") в C++)
scan.close();
}
}