





from math import ceil
from typing import List, Optional, Union

import numpy as np

from ...audio_utils import mel_filter_bank, spectrogram, window_function
from ...feature_extraction_sequence_utils import BatchFeature, SequenceFeatureExtractor
from ...utils import TensorType, logging


UpperCamelCase__											= logging.get_logger(__name__)

class        __SCREAMING_SNAKE_CASE					(     _a       ):
							snake_case     :      Any						     =       ["""audio_values""", """audio_mask"""]






							def __init__(						self  , __lowerCAmelCase=2048  , __lowerCAmelCase=1  , __lowerCAmelCase=[16, 16]  , __lowerCAmelCase=128  , __lowerCAmelCase=44100  , __lowerCAmelCase=86  , __lowerCAmelCase=2048  , __lowerCAmelCase=0.0  , **__lowerCAmelCase  , ):
														super().__init__(
														    feature_size=__lowerCAmelCase  , sampling_rate=__lowerCAmelCase  , padding_value=__lowerCAmelCase  , **__lowerCAmelCase  , )

														UpperCamelCase__				     =			spectrogram_length
														UpperCamelCase__				     =			num_channels
														UpperCamelCase__				     =			patch_size
														UpperCamelCase__				     =			feature_size // self.patch_size[1]
														UpperCamelCase__				     =			n_fft
														UpperCamelCase__				     =			sampling_rate // hop_length_to_sampling_rate
														UpperCamelCase__				     =			sampling_rate
														UpperCamelCase__				     =			padding_value
														UpperCamelCase__				     =			mel_filter_bank(
														    num_frequency_bins=1 + n_fft // 2  , num_mel_filters=__lowerCAmelCase  , min_frequency=0.0  , max_frequency=2_2050.0  , sampling_rate=__lowerCAmelCase  , norm="""slaney"""  , mel_scale="""slaney"""  , ).T






							def 				_lowerCamelCase		(						self  , __lowerCAmelCase  ):
														UpperCamelCase__				     =			spectrogram(
														    __lowerCAmelCase  , window_function(self.n_fft  , """hann"""  )  , frame_length=self.n_fft  , hop_length=self.hop_length  , power=2.0  , mel_filters=self.mel_filters.T  , log_mel="""dB"""  , db_range=80.0  , )
														UpperCamelCase__				     =			log_spec[:, :-1]
														UpperCamelCase__				     =			log_spec - 20.0
														UpperCamelCase__				     =			np.clip(log_spec / 40.0  , -2.0  , 0.0  ) + 1.0
														return log_spec







							def __call__(						self  , __lowerCAmelCase  , __lowerCAmelCase = None  , __lowerCAmelCase = True  , __lowerCAmelCase = None  , __lowerCAmelCase = False  , __lowerCAmelCase = False  , **__lowerCAmelCase  , ):

														if sampling_rate is not None:
																					if sampling_rate != self.sampling_rate:
																												raise ValueError(
																												    """This feature extractor is set to support sampling rate"""
																												    f""" of {self.sampling_rate}. Please make sure that the provided `raw_speech` input was sampled"""
																												    f""" with {self.sampling_rate} and not {sampling_rate}."""  )
														else:
																					logger.warning(
																					    """It is strongly recommended to pass the `sampling_rate` argument to this function. """
																					    """Failing to do so can result in silent errors that might be hard to debug."""  )

														UpperCamelCase__				     =			isinstance(__lowerCAmelCase  , np.ndarray  ) and len(raw_speech.shape  ) > 1
														if is_batched_numpy and len(raw_speech.shape  ) > 2:
																					raise ValueError(f"""Only mono-channel audio is supported for input to {self}"""  )
														UpperCamelCase__				     =			is_batched_numpy or (
														    isinstance(__lowerCAmelCase  , (list, tuple)  ) and (isinstance(raw_speech[0]  , (np.ndarray, tuple, list)  ))
														)
														if is_batched:
																					UpperCamelCase__				     =			[np.asarray([speech]  , dtype=np.floataa  ).T for speech in raw_speech]
														elif not is_batched and not isinstance(__lowerCAmelCase  , np.ndarray  ):
																					UpperCamelCase__				     =			np.asarray(__lowerCAmelCase  , dtype=np.floataa  )
														elif isinstance(__lowerCAmelCase  , np.ndarray  ) and raw_speech.dtype is np.dtype(np.floataa  ):
																					UpperCamelCase__				     =			raw_speech.astype(np.floataa  )
														# always return batch
														if not is_batched:
																					UpperCamelCase__				     =			[np.asarray([raw_speech]  ).T]

														# Convert audio signals to log mel spectrograms, truncate by time axis
														UpperCamelCase__				     =			[
														    self._np_extract_fbank_features(waveform.squeeze()  ).T[: self.spectrogram_length] for waveform in raw_speech
														]
														if isinstance(audio_features[0]  , __lowerCAmelCase  ):
																					UpperCamelCase__				     =			[np.asarray(__lowerCAmelCase  , dtype=np.floataa  ) for feature in audio_features]

														# Create audio attention mask
														UpperCamelCase__				     =			max(
														    [ceil(feature.shape[0] / self.patch_size[0]  ) * self.freq_len for feature in audio_features]  )  # The maximum number of audio patches in a batch
														if return_attention_mask:
																					UpperCamelCase__				     =			[
																					    (ceil(feature.shape[0] / self.patch_size[0]  ) * self.freq_len) * [1]
																					    + (max_patch_len - ceil(feature.shape[0] / self.patch_size[0]  ) * self.freq_len) * [0]
																					    for feature in audio_features
																					]
																					UpperCamelCase__				     =			np.array(__lowerCAmelCase  ).astype(np.floataa  )

														# convert into correct format for padding
														UpperCamelCase__				     =			max_patch_len // self.freq_len * self.patch_size[0]  # The maximum audio size in a batch
														UpperCamelCase__				     =			np.ones([len(__lowerCAmelCase  ), 1, max_time_len, self.feature_size]  ).astype(np.floataa  )
														UpperCamelCase__				     =			padded_audio_features * self.padding_value
														for i in range(len(__lowerCAmelCase  )  ):
																					UpperCamelCase__				     =			audio_features[i]
																					UpperCamelCase__				     =			feature

														# return as BatchFeature
														if return_attention_mask:
																					UpperCamelCase__				     =			{"""audio_values""": padded_audio_features, """audio_mask""": audio_mask}
														else:
																					UpperCamelCase__				     =			{"""audio_values""": padded_audio_features}

														UpperCamelCase__				     =			BatchFeature(data=__lowerCAmelCase  , tensor_type=__lowerCAmelCase  )
														return encoded_inputs











import math





def     _UpperCamelCase     (a__   :int       ):






							"""simple docstring"""





							UpperCamelCase__				     =			[True] * n
							UpperCamelCase__				     =			False
							UpperCamelCase__				     =			False
							UpperCamelCase__				     =			True

							for i in range(3   ,			int(n**0.5 + 1       )   ,			2       ):
														UpperCamelCase__				     =			i * 2
														while index < n:
																					UpperCamelCase__				     =			False
																					UpperCamelCase__				     =			index + i

							UpperCamelCase__				     =			[2]

							for i in range(3   ,			a__   ,			2       ):
														if is_prime[i]:
																					primes.append(a__       )

							return primes





def     _UpperCamelCase     (a__   :int = 9999_6666_3333       ):






							"""simple docstring"""





							UpperCamelCase__				     =			math.floor(math.sqrt(a__       )       ) + 100
							UpperCamelCase__				     =			prime_sieve(a__       )

							UpperCamelCase__				     =			0
							UpperCamelCase__				     =			0
							UpperCamelCase__				     =			primes[prime_index]

							while (last_prime**2) <= limit:
														UpperCamelCase__				     =			primes[prime_index + 1]

														UpperCamelCase__				     =			last_prime**2
														UpperCamelCase__				     =			next_prime**2

														# Get numbers divisible by lps(current)
														UpperCamelCase__				     =			lower_bound + last_prime
														while upper_bound > current <= limit:
																					matches_sum += current
																					current += last_prime

														# Reset the upper_bound
														while (upper_bound - next_prime) > limit:
																					upper_bound -= next_prime

														# Add the numbers divisible by ups(current)
														UpperCamelCase__				     =			upper_bound - next_prime
														while current > lower_bound:
																					matches_sum += current
																					current -= next_prime

														# Remove the numbers divisible by both ups and lps
														UpperCamelCase__				     =			0
														while upper_bound > current <= limit:
																					if current <= lower_bound:
																												# Increment the current number
																												current += last_prime * next_prime
																												continue

																					if current > limit:
																												break

																					# Remove twice since it was added by both ups and lps
																					matches_sum -= current * 2

																					# Increment the current number
																					current += last_prime * next_prime

														# Setup for next pair
														UpperCamelCase__				     =			next_prime
														prime_index += 1

							return matches_sum


if __name__ == "__main__":
					print(solution())




