Let $a,q$ be a positive integers. I am trying to evaluate the following sum:
$\sum\_{\substack{1<a<q \\(a,q)>1 \\ (a+1,q)>1}}1$. Is there a formula that exists to calculate such sums?


Here is an example: 


Let $q=15$.
We have the following multiple of divisors:
1,2,3,5,6,9,10,12,15.


But since the two pairs (5,6) and (9,10) are consecutives numbers bigger than one but less than q, we get : 


$\sum\_{\substack{1<a<15 \\(a,15)>1 \\ (a+1,15)>1}}1=2$.



Sum of $\sum_{\substack{1<a<q \\(a,q)>1 \\ (a+1,q)>1}}1$
At first, we count the number of residues $a$ for which both $a$ and $a+1$ are coprime with $n$. Let $q=\prod p\_i^{k\_i}$ be a factorization of $q$. For any $p\_i$, there exist $p\_i-2$ admissible remainders modulo $p\_i$ (forgotten remainders are 0 and $-1$), thus $(p\_i-2)p\_i^{k\_i-1}$ admissible remainders modulo $p\_i^{k\_i}$, thus by Chinese Remainders Theorem the answer equals $$F(q):=\prod (p\_i-2)p\_i^{k\_i-1}=q\prod(1-2/p\_i).$$
Now your question. There exist $\varphi(q)$ residues $a$ for which $(a,q)=1$, as many residues for which $(a+1,q)=1$, $F(q)$ residues for which both $(a,q)=1$, $(a+1,q)=1$. Thus there exist $\varphi(q)-F(q)$ residues $a$ for which $(a,q)=1$ and $(a+1,q)>1$. But the total number of $a$ for which $(a+1,q)>1$ equals $q-\varphi(q)$. Therefore the answer to your initial question is $q-2\varphi(q)+F(q)$.


