A plane geometric figure of $n$ sides with the vertices $A_1,A_2,A_3,\dots, A_n$ ($A_i$ is adjacent to $A_{i+1}$ for every $i$ integer where $1\leq i\leq n-1$ and $A_n$ is adjacent to $A_1$) is called [i]brazilian[/i] if:
I - The segment $A_jA_{j+1}$ is equal to $(\sqrt{2})^{j-1}$, for every $j$ with $1\leq j\leq n-1$.
II- The angles $\angle A_kA_{k+1}A_{k+2}=135^{\circ}$, for every $k$ with $1\leq k\leq n-2$.
[b]Note 1:[/b] The figure can be convex or not convex, and your sides can be crossed.
[b]Note 2:[/b] The angles are in counterclockwise.
a) Find the length of the segment $A_nA_1$ for a brazilian figure with $n=5$.
b) Find the length of the segment $A_nA_1$ for a brazilian figure with $n\equiv 1$ (mod $4$).
Let's break down the problem into two parts: (a) finding the length of the segment \( A_nA_1 \) for \( n = 5 \), and (b) finding the length of the segment \( A_nA_1 \) for \( n \equiv 1 \pmod{4} \).

### Part (a): Finding the length of the segment \( A_nA_1 \) for \( n = 5 \)

1. **Define the vertices using complex numbers:**
   - Let \( A_1 = 0 \) and \( A_2 = 1 \).
   - The segment \( A_jA_{j+1} = (\sqrt{2})^{j-1} \) for \( 1 \leq j \leq n-1 \).

2. **Express the vertices in terms of complex numbers:**
   - Since \( A_jA_{j+1} = (1+i)^{j-1} \), we can write the vertices as:
     \[
     A_1 = 0, \quad A_2 = 1, \quad A_3 = 1 + (1+i), \quad A_4 = 1 + (1+i) + (1+i)^2, \quad A_5 = 1 + (1+i) + (1+i)^2 + (1+i)^3
     \]

3. **Sum the series to find \( A_5 \):**
   - The series is a geometric series with the common ratio \( 1+i \):
     \[
     S = 1 + (1+i) + (1+i)^2 + (1+i)^3
     \]
   - The sum of the first \( n-1 \) terms of a geometric series is given by:
     \[
     S = \frac{(1+i)^{n-1} - 1}{(1+i) - 1}
     \]
   - For \( n = 5 \):
     \[
     S = \frac{(1+i)^4 - 1}{i}
     \]

4. **Calculate \( (1+i)^4 \):**
   - Using De Moivre's theorem:
     \[
     (1+i)^4 = (\sqrt{2} e^{i\pi/4})^4 = 4 e^{i\pi} = 4(-1) = -4
     \]
   - Therefore:
     \[
     S = \frac{-4 - 1}{i} = \frac{-5}{i} = 5i
     \]

5. **Find the magnitude of \( S \):**
   - The length of the segment \( A_5A_1 \) is the magnitude of \( S \):
     \[
     |S| = |5i| = 5
     \]

### Part (b): Finding the length of the segment \( A_nA_1 \) for \( n \equiv 1 \pmod{4} \)

1. **Generalize the sum for \( n = 4k + 1 \):**
   - The sum of the series for \( n = 4k + 1 \) is:
     \[
     S = \frac{(1+i)^{4k} - 1}{i}
     \]

2. **Calculate \( (1+i)^{4k} \):**
   - Using De Moivre's theorem:
     \[
     (1+i)^{4k} = (\sqrt{2} e^{i\pi/4})^{4k} = (2^2)^k e^{i\pi k} = 4^k e^{i\pi k}
     \]
   - Since \( e^{i\pi k} = (-1)^k \):
     \[
     (1+i)^{4k} = 4^k (-1)^k
     \]

3. **Substitute back into the sum:**
   - The sum becomes:
     \[
     S = \frac{4^k (-1)^k - 1}{i}
     \]

4. **Simplify the expression:**
   - The length of the segment \( A_nA_1 \) is the magnitude of \( S \):
     \[
     |S| = \left| \frac{4^k (-1)^k - 1}{i} \right| = \left| 4^k (-1)^k - 1 \right|
     \]
   - This simplifies to:
     \[
     |S| = 4^k - (-1)^k
     \]

The final answer is \( \boxed{4^{\frac{n-1}{4}} - (-1)^{\frac{n-1}{4}}} \)