Cod sursa(job #2595132)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 7 aprilie 2020 10:58:14
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("pascal.in");
ofstream fout("pascal.out");

const int DIM = 5e6 + 1;

int cnt2[DIM];
int cnt3[DIM];
int cnt5[DIM];

main()
{
	int n, k;
	fin >> n >> k;
	
	for(int i = 2; i <= n; i += 2)
	{
		cnt2[i] = cnt2[i / 2] + 1;
	}
	
	for(int i = 3; i <= n; i += 3)
	{
		cnt3[i] = cnt3[i / 3] + 1;
	}
	
	for(int i = 5; i <= n; i += 5)
	{
		cnt5[i] = cnt5[i / 5] + 1;
	}
	
	for(int i = 2; i <= n; ++i)
	{
		cnt2[i] += cnt2[i - 1];
		cnt3[i] += cnt3[i - 1];
		cnt5[i] += cnt5[i - 1];
	}
	
	int ans = 0;
	
	for(int i = 0; i <= n; ++i)
	{
		int nr2 = cnt2[n] - cnt2[i] - cnt2[n - i];
		int nr3 = cnt3[n] - cnt3[i] - cnt3[n - i];
		int nr5 = cnt5[n] - cnt5[i] - cnt5[n - i];
		
		if(k == 2 && nr2)
			++ans;
		
		if(k == 3 && nr3)
			++ans;
		
		if(k == 4 && nr2 > 1)
			++ans;
		
		if(k == 5 && nr5)
			++ans;
		
		if(k == 6 && nr2 && nr3)
			++ans;
	}
	
	fout << ans << '\n';
}