For any positive integer $n$, and $i=1,2$, let $f_{i}(n)$ denote the number of divisors of $n$ of the form $3 k+i$ (including $1$ and $n$ ). Define, for any positive integer $n$, $$f(n)=f_{1}(n)-f_{2}(n)$$ Find the value of $f\left(5^{2022}\right)$ and $f\left(21^{2022}\right)$.
1. **Part (a): Calculation of \( f(5^{2022}) \)**

   We need to evaluate the number of divisors of \( 5^{2022} \) of the form \( 3k+1 \) and \( 3k+2 \).

   - **Divisors of the form \( 3k+1 \)**:
     The divisors of \( 5^{2022} \) are \( 1, 5, 5^2, \ldots, 5^{2022} \). We need to find which of these are of the form \( 3k+1 \).
     Notice that \( 5^n \equiv 1 \pmod{3} \) if \( n \) is even. Therefore, the exponents \( n \) must be even.
     The even numbers between 0 and 2022 (inclusive) are \( 0, 2, 4, \ldots, 2022 \). This is an arithmetic sequence with the first term 0 and common difference 2.
     The number of terms in this sequence is:
     \[
     \frac{2022 - 0}{2} + 1 = 1012
     \]
     Thus, \( f_1(5^{2022}) = 1012 \).

   - **Divisors of the form \( 3k+2 \)**:
     Similarly, \( 5^n \equiv 2 \pmod{3} \) if \( n \) is odd. Therefore, the exponents \( n \) must be odd.
     The odd numbers between 0 and 2022 (inclusive) are \( 1, 3, 5, \ldots, 2021 \). This is an arithmetic sequence with the first term 1 and common difference 2.
     The number of terms in this sequence is:
     \[
     \frac{2021 - 1}{2} + 1 = 1011
     \]
     Thus, \( f_2(5^{2022}) = 1011 \).

   Therefore, we have:
   \[
   f(5^{2022}) = f_1(5^{2022}) - f_2(5^{2022}) = 1012 - 1011 = 1
   \]

2. **Part (b): Calculation of \( f(21^{2022}) \)**

   We need to evaluate the number of divisors of \( 21^{2022} \) of the form \( 3k+1 \) and \( 3k+2 \).

   - **Divisors of \( 21^{2022} \)**:
     Notice that \( 21 = 3 \cdot 7 \). Therefore, \( 21^{2022} = 3^{2022} \cdot 7^{2022} \).

     - **Divisors of \( 3^{2022} \)**:
       Since \( 3 \equiv 0 \pmod{3} \), any power of 3 will be \( 0 \pmod{3} \). Therefore, \( 3^{2022} \) has no divisors of the form \( 3k+1 \) or \( 3k+2 \).

     - **Divisors of \( 7^{2022} \)**:
       Since \( 7 \equiv 1 \pmod{3} \), any power of 7 will be \( 1 \pmod{3} \). Therefore, all divisors of \( 7^{2022} \) are of the form \( 3k+1 \).

       The divisors of \( 7^{2022} \) are \( 1, 7, 7^2, \ldots, 7^{2022} \). There are \( 2022 + 1 = 2023 \) such divisors.

       Thus, \( f_1(21^{2022}) = 2023 \) and \( f_2(21^{2022}) = 0 \).

   Therefore, we have:
   \[
   f(21^{2022}) = f_1(21^{2022}) - f_2(21^{2022}) = 2023 - 0 = 2023
   \]

The final answer is \( \boxed{ f(5^{2022}) = 1 } \) and \( f(21^{2022}) = 2023 \).