< Summary

Information
Class: LeetCode.Algorithms.CheckIfAnyElementHasPrimeFrequency.CheckIfAnyElementHasPrimeFrequencyBase
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfAnyElementHasPrimeFrequency\CheckIfAnyElementHasPrimeFrequencyBase.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
IsPrime(...)100%11100%
GeneratePrimes(...)100%1818100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfAnyElementHasPrimeFrequency\CheckIfAnyElementHasPrimeFrequencyBase.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.CheckIfAnyElementHasPrimeFrequency;
 13
 14public abstract class CheckIfAnyElementHasPrimeFrequencyBase : ICheckIfAnyElementHasPrimeFrequency
 15{
 16    protected const int Count = 101;
 17
 118    private static readonly bool[] Primes = GeneratePrimes(Count);
 19
 20    public abstract bool CheckPrimeFrequency(int[] nums);
 21
 22    protected static bool IsPrime(int number)
 11923    {
 11924        return Primes[number];
 11925    }
 26
 27    private static bool[] GeneratePrimes(int max)
 128    {
 129        var isPrime = new bool[max + 1];
 30
 131        if (max >= 2)
 132        {
 133            isPrime[2] = true;
 134        }
 35
 10236        for (var i = 3; i <= max; i += 2)
 5037        {
 5038            isPrime[i] = true;
 5039        }
 40
 1041        for (var p = 3; p * p <= max; p += 2)
 442        {
 443            if (!isPrime[p])
 144            {
 145                continue;
 46            }
 47
 6248            for (var multiple = p * p; multiple <= max; multiple += p * 2)
 2849            {
 2850                isPrime[multiple] = false;
 2851            }
 352        }
 53
 154        if (max >= 2)
 155        {
 156            isPrime[2] = true;
 157        }
 58
 159        if (max >= 3)
 160        {
 161            isPrime[3] = true;
 162        }
 63
 164        if (max >= 0)
 165        {
 166            isPrime[0] = false;
 167        }
 68
 169        if (max >= 1)
 170        {
 171            isPrime[1] = false;
 172        }
 73
 174        return isPrime;
 175    }
 76}