

'''simple docstring'''
import torch
from torch import nn
class 					_snake_case		(nn.Module):






			def __init__(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case			,_snake_case=1			,_snake_case=False     ):
				super().__init__()

				UpperCAmelCase_     :      List[Any]						=  n_token
				UpperCAmelCase_     :      int						=  d_embed
				UpperCAmelCase_     :      Optional[Any]						=  d_proj

				UpperCAmelCase_     :      Tuple						=  cutoffs + [n_token]
				UpperCAmelCase_     :      List[str]						=  [0] + self.cutoffs
				UpperCAmelCase_     :      str						=  div_val

				UpperCAmelCase_     :      List[str]						=  self.cutoffs[0]
				UpperCAmelCase_     :      Optional[int]						=  len(self.cutoffs     ) - 1
				UpperCAmelCase_     :      Tuple						=  self.shortlist_size + self.n_clusters

				if self.n_clusters > 0:
					UpperCAmelCase_     :      Optional[int]						=  nn.Parameter(torch.zeros(self.n_clusters			,self.d_embed     )     )
					UpperCAmelCase_     :      Union[str, Any]						=  nn.Parameter(torch.zeros(self.n_clusters     )     )

				UpperCAmelCase_     :      str						=  nn.ModuleList()
				UpperCAmelCase_     :      List[Any]						=  nn.ParameterList()

				if div_val == 1:
					for i in range(len(self.cutoffs     )     ):
						if d_proj != d_embed:
							self.out_projs.append(nn.Parameter(torch.FloatTensor(_snake_case			,_snake_case     )     )     )
						else:
							self.out_projs.append(_snake_case     )

					self.out_layers.append(nn.Linear(_snake_case			,_snake_case     )     )
				else:
					for i in range(len(self.cutoffs     )     ):
						UpperCAmelCase_					,					UpperCAmelCase_     :      List[str]						=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
						UpperCAmelCase_     :      Union[str, Any]						=  d_embed // (div_val**i)

						self.out_projs.append(nn.Parameter(torch.FloatTensor(_snake_case			,_snake_case     )     )     )

						self.out_layers.append(nn.Linear(_snake_case			,r_idx - l_idx     )     )

				UpperCAmelCase_     :      Tuple						=  keep_order






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case			,_snake_case			,_snake_case     ):
				if proj is None:
					UpperCAmelCase_     :      int						=  nn.functional.linear(_snake_case			,_snake_case			,bias=_snake_case     )
				else:
					# if CUDA_MAJOR <= 9 and CUDA_MINOR <= 1:
					UpperCAmelCase_     :      Tuple						=  nn.functional.linear(_snake_case			,proj.t().contiguous()     )
					UpperCAmelCase_     :      Dict						=  nn.functional.linear(_snake_case			,_snake_case			,bias=_snake_case     )
					# else:
					#     logit = torch.einsum('bd,de,ev->bv', (hidden, proj, weight.t()))
					#     if bias is not None:
					#         logit = logit + bias

				return logit






			def 		UpperCamelCase__							(  self			,_snake_case			,_snake_case=None			,_snake_case=False     ):

				if labels is not None:
					# Shift so that tokens < n predict n
					UpperCAmelCase_     :      Optional[Any]						=  hidden[..., :-1, :].contiguous()
					UpperCAmelCase_     :      Any						=  labels[..., 1:].contiguous()
					UpperCAmelCase_     :      Dict						=  hidden.view(-1			,hidden.size(-1     )     )
					UpperCAmelCase_     :      Union[str, Any]						=  labels.view(-1     )
					if hidden.size(0     ) != labels.size(0     ):
						raise RuntimeError("Input and labels should have the same size in the batch dimension."     )
				else:
					UpperCAmelCase_     :      Optional[Any]						=  hidden.view(-1			,hidden.size(-1     )     )

				if self.n_clusters == 0:
					UpperCAmelCase_     :      Any						=  self._compute_logit(_snake_case			,self.out_layers[0].weight			,self.out_layers[0].bias			,self.out_projs[0]     )
					if labels is not None:
						UpperCAmelCase_     :      Any						=  labels != -1_00
						UpperCAmelCase_     :      Any						=  torch.zeros_like(_snake_case			,dtype=hidden.dtype			,device=hidden.device     )
						UpperCAmelCase_     :      Union[str, Any]						=  (
						    -nn.functional.log_softmax(_snake_case			,dim=-1     )[mask].gather(1			,labels[mask].unsqueeze(1     )     ).squeeze(1     )
						)
					else:
						UpperCAmelCase_     :      Optional[int]						=  nn.functional.log_softmax(_snake_case			,dim=-1     )
				else:
					# construct weights and biases
					UpperCAmelCase_					,					UpperCAmelCase_     :      List[str]						=  [], []
					for i in range(len(self.cutoffs     )     ):
						if self.div_val == 1:
							UpperCAmelCase_					,					UpperCAmelCase_     :      Union[str, Any]						=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
							UpperCAmelCase_     :      Any						=  self.out_layers[0].weight[l_idx:r_idx]
							UpperCAmelCase_     :      List[str]						=  self.out_layers[0].bias[l_idx:r_idx]
						else:
							UpperCAmelCase_     :      Optional[Any]						=  self.out_layers[i].weight
							UpperCAmelCase_     :      str						=  self.out_layers[i].bias

						if i == 0:
							UpperCAmelCase_     :      Union[str, Any]						=  torch.cat([weight_i, self.cluster_weight]			,dim=0     )
							UpperCAmelCase_     :      Union[str, Any]						=  torch.cat([bias_i, self.cluster_bias]			,dim=0     )

						weights.append(_snake_case     )
						biases.append(_snake_case     )

					UpperCAmelCase_					,					UpperCAmelCase_					,					UpperCAmelCase_     :      Dict						=  weights[0], biases[0], self.out_projs[0]

					UpperCAmelCase_     :      Optional[Any]						=  self._compute_logit(_snake_case			,_snake_case			,_snake_case			,_snake_case     )
					UpperCAmelCase_     :      Dict						=  nn.functional.log_softmax(_snake_case			,dim=1     )

					if labels is None:
						UpperCAmelCase_     :      int						=  hidden.new_empty((head_logit.size(0     ), self.n_token)     )
					else:
						UpperCAmelCase_     :      Any						=  torch.zeros_like(_snake_case			,dtype=hidden.dtype			,device=hidden.device     )

					UpperCAmelCase_     :      int						=  0
					UpperCAmelCase_     :      Optional[Any]						=  [0] + self.cutoffs
					for i in range(len(_snake_case     ) - 1     ):
						UpperCAmelCase_					,					UpperCAmelCase_     :      Dict						=  cutoff_values[i], cutoff_values[i + 1]

						if labels is not None:
							UpperCAmelCase_     :      int						=  (labels >= l_idx) & (labels < r_idx)
							UpperCAmelCase_     :      Any						=  mask_i.nonzero().squeeze()

							if indices_i.numel() == 0:
								continue

							UpperCAmelCase_     :      Dict						=  labels.index_select(0			,_snake_case     ) - l_idx
							UpperCAmelCase_     :      List[Any]						=  head_logprob.index_select(0			,_snake_case     )
							UpperCAmelCase_     :      Optional[int]						=  hidden.index_select(0			,_snake_case     )
						else:
							UpperCAmelCase_     :      Optional[Any]						=  hidden

						if i == 0:
							if labels is not None:
								UpperCAmelCase_     :      List[str]						=  head_logprob_i.gather(1			,target_i[:, None]     ).squeeze(1     )
							else:
								UpperCAmelCase_     :      Optional[int]						=  head_logprob[:, : self.cutoffs[0]]
						else:
							UpperCAmelCase_					,					UpperCAmelCase_					,					UpperCAmelCase_     :      Any						=  weights[i], biases[i], self.out_projs[i]

							UpperCAmelCase_     :      Union[str, Any]						=  self._compute_logit(_snake_case			,_snake_case			,_snake_case			,_snake_case     )
							UpperCAmelCase_     :      int						=  nn.functional.log_softmax(_snake_case			,dim=1     )
							UpperCAmelCase_     :      int						=  self.cutoffs[0] + i - 1  # No probability for the head cluster
							if labels is not None:
								UpperCAmelCase_     :      str						=  head_logprob_i[:, cluster_prob_idx] + tail_logprob_i.gather(
								    1			,target_i[:, None]     ).squeeze(1     )
							else:
								UpperCAmelCase_     :      Union[str, Any]						=  head_logprob[:, cluster_prob_idx, None] + tail_logprob_i
								UpperCAmelCase_     :      Optional[int]						=  logprob_i

						if labels is not None:
							if (hasattr(self			,"keep_order"     ) and self.keep_order) or keep_order:
								out.index_copy_(0			,_snake_case			,-logprob_i     )
							else:
								out[offset : offset + logprob_i.size(0     )].copy_(-logprob_i     )
							offset += logprob_i.size(0     )

				return out






			def 		UpperCamelCase__							(  self			,_snake_case     ):
				if self.n_clusters == 0:
					UpperCAmelCase_     :      Dict						=  self._compute_logit(_snake_case			,self.out_layers[0].weight			,self.out_layers[0].bias			,self.out_projs[0]     )
					return nn.functional.log_softmax(_snake_case			,dim=-1     )
				else:
					# construct weights and biases
					UpperCAmelCase_					,					UpperCAmelCase_     :      Union[str, Any]						=  [], []
					for i in range(len(self.cutoffs     )     ):
						if self.div_val == 1:
							UpperCAmelCase_					,					UpperCAmelCase_     :      Any						=  self.cutoff_ends[i], self.cutoff_ends[i + 1]
							UpperCAmelCase_     :      Tuple						=  self.out_layers[0].weight[l_idx:r_idx]
							UpperCAmelCase_     :      Any						=  self.out_layers[0].bias[l_idx:r_idx]
						else:
							UpperCAmelCase_     :      str						=  self.out_layers[i].weight
							UpperCAmelCase_     :      str						=  self.out_layers[i].bias

						if i == 0:
							UpperCAmelCase_     :      List[Any]						=  torch.cat([weight_i, self.cluster_weight]			,dim=0     )
							UpperCAmelCase_     :      List[str]						=  torch.cat([bias_i, self.cluster_bias]			,dim=0     )

						weights.append(_snake_case     )
						biases.append(_snake_case     )

					UpperCAmelCase_					,					UpperCAmelCase_					,					UpperCAmelCase_     :      List[str]						=  weights[0], biases[0], self.out_projs[0]
					UpperCAmelCase_     :      List[Any]						=  self._compute_logit(_snake_case			,_snake_case			,_snake_case			,_snake_case     )

					UpperCAmelCase_     :      str						=  hidden.new_empty((head_logit.size(0     ), self.n_token)     )
					UpperCAmelCase_     :      List[Any]						=  nn.functional.log_softmax(_snake_case			,dim=1     )

					UpperCAmelCase_     :      Optional[int]						=  [0] + self.cutoffs
					for i in range(len(_snake_case     ) - 1     ):
						UpperCAmelCase_					,					UpperCAmelCase_     :      int						=  cutoff_values[i], cutoff_values[i + 1]

						if i == 0:
							UpperCAmelCase_     :      Optional[Any]						=  head_logprob[:, : self.cutoffs[0]]
						else:
							UpperCAmelCase_					,					UpperCAmelCase_					,					UpperCAmelCase_     :      Optional[int]						=  weights[i], biases[i], self.out_projs[i]

							UpperCAmelCase_     :      int						=  self._compute_logit(_snake_case			,_snake_case			,_snake_case			,_snake_case     )
							UpperCAmelCase_     :      int						=  nn.functional.log_softmax(_snake_case			,dim=1     )

							UpperCAmelCase_     :      Tuple						=  head_logprob[:, -i] + tail_logprob_i
							UpperCAmelCase_     :      Union[str, Any]						=  logprob_i

					return out






from math import isqrt, loga
def 							SCREAMING_SNAKE_CASE_	(					UpperCAmelCase_	:     int				)			->						list[int]:
       SCREAMING_SNAKE_CASE_							:				int		=[True] * max_number
       for i in range(2			,							isqrt(max_number - 1				) + 1				):
              if is_prime[i]:
                     for j in range(i**2			,							UpperCAmelCase_			,							UpperCAmelCase_				):
                            SCREAMING_SNAKE_CASE_							:				Dict		=False

       return [i for i in range(2			,							UpperCAmelCase_				) if is_prime[i]]
def 							SCREAMING_SNAKE_CASE_	(					UpperCAmelCase_	:     int = 8_0_0_8_0_0			,							UpperCAmelCase_	:     int = 8_0_0_8_0_0				)			->						int:
       SCREAMING_SNAKE_CASE_							:				str		=degree * loga(UpperCAmelCase_				)
       SCREAMING_SNAKE_CASE_							:				List[Any]		=int(UpperCAmelCase_				)
       SCREAMING_SNAKE_CASE_							:				int		=calculate_prime_numbers(UpperCAmelCase_				)

       SCREAMING_SNAKE_CASE_							:				int		=0
       SCREAMING_SNAKE_CASE_							:				List[Any]		=0
       SCREAMING_SNAKE_CASE_							:				Any		=len(UpperCAmelCase_				) - 1
       while left < right:
              while (
                  prime_numbers[right] * loga(prime_numbers[left]				)
                  + prime_numbers[left] * loga(prime_numbers[right]				)
                  > upper_bound
              ):
                     right -= 1
              hybrid_integers_count += right - left
              left += 1

       return hybrid_integers_count


if __name__ == "__main__":
 print(F"{solution() = }")
