Q[M_] := Log[M] ;
Major0[x_,  M_]  :=  
        If[ x  ≤  (1.0*Q[M]/M),  1,  
          0];
Major1[x_,  M_]  :=  
        If[ 1  -  (1.0*Q[M]/M)  ≤  x,  1,  
          0];
f[x_, M_]  :=  
        Sum[Cos[2.0 * Pi * Prime[n] * x],  {n, 1, 
            M}];
RelPrime[a_,  q_]  :=  
        KroneckerDelta[1,  GCD[a, q]];
CharMajor[x_, 
          M_]  :=  
Sum[  
      Sum[   
             If[ (1.0*
                          a/q)   -  (1.0*Q[M]/M) ≤  
                    x  &&  x  ≤   (1.0*a/q)  +  (1.0*
                          Q[M]/M),  RelPrime[a, q],  
                0], 
   {a, 1, 
                q - 1}], 
    {q, 2,  
              Floor[Q[M] ]}
  ]    +  
          Major0[x, M]  +  Major1[x, M];

    
CharMinor[x_, M_] := 
        1 - CharMajor[x, M];
MajorArc[x_, M_] :=  
        If[CharMajor[x, M] > 0, f[x, M], 0];
MinorArc[x_, M_] :=  
        If[CharMinor[x, M] > 0, f[x, M], 0];
fweight[x_, M_] :=  
        Sum[    Log[Prime[n]]*Cos[2.0 * Pi * Prime[n] * x],  {n, 
            1, M}];
MinorArcWeight[x_, M_] := 
        If[CharMinor[x, M] > 0, fweight[x, M], 
          0];
fweightarray[x_, M_] := 
        Sum[    Log[ArrayPrime[n]]*
            Cos[2.0 * Pi * ArrayPrime[n] * x],  {n, 1, 
            M}];
MinorArcWeightArray[x_, M_] := 
        If[CharMinor[x, M] > 0, fweightarray[x, M], 0];

Do[ 
      ArrayPrime[n]  =  Prime[n],  {n,  
        1000000}]
g[x_, M_]  :=  
      Sum[Cos[2.0 * Pi * ArrayPrime[n] * x],  {n, 1, 
          M}]

Plot[{MajorArc[x,  100],  -100,  100}, {x,  .495,  .505}, 
      PlotRange -> {-100, 100}]

Plot[ {MinorArc[x, 200],  -200,  200}, {x, 0, 1}, 
      PlotRange -> {-201, 201}]

Plot[ {MinorArc[x, 200],  -200,  200}, {x, 0, 1}, 
      PlotRange -> {-201, 201}]

Q[200.0]

Plot[ {MajorArc[x, 200],  -200,  200}, {x,  .195,  .205}, 
      PlotRange -> {-201, 201}]

Plot[ CharMajor[x,  200],  {x, 0, 1}]

Plot[CharMajor[x, 500], {x, 0, 1}]

Plot[CharMajor[x, 1000], {x, 0, 1}]

Plot[CharMajor[x, 10000], {x, 0, 1}]

Plot[CharMajor[x, 100000], {x, 0, 1}]

Plot[CharMajor[x, 1000000], {x, 0, 1}]

Plot[MinorArcWeightArray[x, 500], {x, 0, 1}, 
      PlotRange -> {-500, 500}]

Show[%, PlotRange -> {-700, 700}]

Plot[MinorArcWeightArray[x, 500], {x, 0.9, 0.95}, 
      PlotRange -> {-800, 800}]

Plot[{MinorArcWeightArray[x, 500], -300, 550}, {x, 0.926, 0.939}, 
      PlotRange -> {-800, 800}]

Plot[MinorArcWeightArray[x, 1000], {x, 0, 1}, 
      PlotRange -> {-1500, 1500}]

Plot[MinorArcWeightArray[x, 1000], {x,  .5,  .8}, 
      PlotRange -> {-1500, 1500}]

Plot[MinorArcWeightArray[x, 1000], {x,  .69,  .71}, 
      PlotRange -> {-1500, 1500}]

Plot[{MinorArcWeightArray[x, 1000],  -2000,  
        2000}, {x,  .699,  .701}, 
      PlotRange -> {-2200, 2200}]

Plot[{MinorArcWeightArray[x, 500], -900, 900}, {x, 0.098,  .102}, 
      PlotRange -> {-1000, 1000}]

Plot[MinorArcWeightArray[x, 10000], {x, 0, 1}, 
      PlotRange -> {-15000, 15000}]

Show[%, PlotRange -> {-7000, 7000}]

Plot[MinorArcWeightArray[x, 10000], {x, 0.095, 0.11}, 
      PlotRange -> {-7000, 7000}]

Show[%, PlotRange -> {-4000, 9000}]

Plot[MinorArcWeightArray[x, 10000], {x, 0.0945, 0.096}, 
      PlotRange -> {-9000, 9000}]

Plot[{MinorArcWeightArray[x, 10000],  -9000, 9000}, {x, 0.09515, 
        0.09530}, PlotRange -> {-10000, 10000}]

Plot[MinorArc[x, 100000], {x, 0, 1},  
      PlotRange  ->  {-200, 200}]

Plot[MinorArc[x, 100000], {x, 0,  .5}, 
      PlotRange -> {-10000, 10000}]

Show[%, PlotRange -> {-1000, 1000}]

Plot[MinorArc[x, 100000], {x,  .5, 1}, 
      PlotRange -> {-1000, 1000}]

Plot[MinorArcWeightArray[x, 100000], {x, 0, 1}, 
      PlotRange -> {-10000, 10000}]

Plot[{MinorArcWeightArray[x, 100000],  -10000,  10000},  {x, 
        0.245, 0.260}, PlotRange -> {-10000, 10000}]

Show[%, PlotRange -> {-12000, 12000}]

Show[%, PlotRange -> {-15000, 15000}]

Show[%, PlotRange -> {-30000, 30000}]

Show[%, PlotRange -> {-25000, 25000}]

Plot[{MinorArcWeightArray[x, 100000],  -10000,  22000},  {x, 
        0.2545, 0.2550}, PlotRange -> {-15000, 25000}]

Show[%, PlotRange -> {-15000, 30000}]

Show[%, PlotRange -> {-10000, 35000}]

Show[%, PlotRange -> {-10000, 50000}]

Show[%, PlotRange -> {-10000, 36000}]

Plot[{MinorArcWeightArray[x, 100000],  -10000,  38000},  {x, 
        0.25488, 0.25492}, PlotRange -> {-10000, 40000}]

Show[%, PlotRange -> {-10000, 45000}]