< 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: 77
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
 14/// <inheritdoc />
 15public abstract class CheckIfAnyElementHasPrimeFrequencyBase : ICheckIfAnyElementHasPrimeFrequency
 16{
 17    protected const int Count = 101;
 18
 119    private static readonly bool[] Primes = GeneratePrimes(Count);
 20
 21    public abstract bool CheckPrimeFrequency(int[] nums);
 22
 23    protected static bool IsPrime(int number)
 11924    {
 11925        return Primes[number];
 11926    }
 27
 28    private static bool[] GeneratePrimes(int max)
 129    {
 130        var isPrime = new bool[max + 1];
 31
 132        if (max >= 2)
 133        {
 134            isPrime[2] = true;
 135        }
 36
 10237        for (var i = 3; i <= max; i += 2)
 5038        {
 5039            isPrime[i] = true;
 5040        }
 41
 1042        for (var p = 3; p * p <= max; p += 2)
 443        {
 444            if (!isPrime[p])
 145            {
 146                continue;
 47            }
 48
 6249            for (var multiple = p * p; multiple <= max; multiple += p * 2)
 2850            {
 2851                isPrime[multiple] = false;
 2852            }
 353        }
 54
 155        if (max >= 2)
 156        {
 157            isPrime[2] = true;
 158        }
 59
 160        if (max >= 3)
 161        {
 162            isPrime[3] = true;
 163        }
 64
 165        if (max >= 0)
 166        {
 167            isPrime[0] = false;
 168        }
 69
 170        if (max >= 1)
 171        {
 172            isPrime[1] = false;
 173        }
 74
 175        return isPrime;
 176    }
 77}