Consider $0=t\_0\leq t\_1\leq...\leq t\_n=1$, $f\_0,...,f\_{n-1}\in\mathbb{Z}$ and $F:[0,1]\to\mathbb{R}$ be such that 


1) $F\equiv f\_i$ on the interval $(t\_i,t\_{t+1})$, for all $i=0,...,n-1$,


2) $\displaystyle \int\_0^1 F(t) dt=\sum\_{i=0}^{n-1}(t\_{i+1}-t\_i)f\_i=0$.


Does there exist an arbitrarily large prime number $p$ and a positive integer $k=k(p)$ such that $q:=p^k$ satisfies


$\displaystyle \sum\_{i=1}^{q-1} F\left(\frac{i}{q}\right)=0$ ?


I know that the answer is YES when all the $t\_j$'s are rational number: if $t\_j=\frac{p\_j}{q\_j}$, then it suffices to choose $q\equiv 1$ mod $\mathrm{lcm}(q\_1,...,q\_{n-1})$.


Any idea for the general case?



Piecewise constant functions with zero average
Thanks to the comments of George Lowther and Greg Martin (for which I am most grateful), I can now show that the answer is YES for infinitely many primes $q$.


**Theorem 1.** Let $t\_1\dots,t\_{n-1}$ be any finite set of real numbers.Then for any $\epsilon>0$ and any integer $r>0$ there are infinitely many primes $q\equiv 1\pmod{r}$ such that
$$\|(q-1)t\_i\|<\epsilon,\qquad i=1,\dots,n-1.\tag{1}$$
Here $\|x\|$ stands for the distance of $x$ to the nearest integer.


**Proof.** Without loss of generality, the numbers $1,t\_1,\dots,t\_{n-1}$ are linearly independent over $\mathbb{Q}$. Indeed, we can express each of them as a $\mathbb{Z}$-linear combination from a suitable basis $\frac{1}{s},t\_1^\*,\dots,t\_{m-1}^\*$ of their $\mathbb{Q}$-linear span, where $s>0$ is an integer. Then the statement for $t\_1,\dots,t\_{n-1}$ follows from the statement for $t\_1^\*,\dots,t\_{m-1}^\*$ (with $\mathrm{lcm}(r,s)$ in place of $r$). When the elements of $1,t\_1,\dots,t\_{n-1}$ are linearly independent over $\mathbb{Q}$,
the statement follows from the stronger result that the vectors $(qt\_1,\dots,qt\_{n-1})$ are dense modulo $1$, as $q$ runs through the primes such that $q\equiv 1\pmod{r}$. This result is essentially due to Vinogradov, with technical improvements by Vaughan and Harman. See Theorem 4 in Harman: Diophantine approximation with primes, J. London Math. Soc. (2) 39 (1989), 405–413. Well, Harman does not have the condition $q\equiv 1\pmod{r}$, but it seems straightforward to incorporate it.


**Theorem 2.** Let $t\_i$, $f\_i$, $F$ be as in the original question but without the assumption $f\_i\in\mathbb{Z}$. Then for any $\epsilon>0$ there is a prime $q$ such that
$$\left|\sum\_{j=1}^{q-1}F\left(\frac{j}{q}\right)\right|<
\epsilon.$$
In particular, if $F$ is integer valued and $\epsilon=1$, then the left hand side is zero.


**Proof.** Assume that $\epsilon>0$ is sufficiently small, namely
$$\epsilon<\|t\_i\|,\qquad i=1,\dots,n-1.\tag{2}$$
By Theorem 1, there is a prime $q$ such that (1) holds.
Observe that
$$\sum\_{j=1}^{q-1}F\left(\frac{j}{q}\right)=\sum\_{i=0}^{n-2}f\_i\bigl([qt\_{i+1}]-[qt\_i]\bigr)+f\_{n-1}\bigl(q-1-[qt\_{n-1}]\bigr),$$
where $[x]$ stands for the integral part of $x$. Here we used that no $\frac{j}{q}$ coincides with any $t\_i$, as follows from (1) and (2). We subtract
$$0=(q-1)\int\_0^1 F(t)dt=\sum\_{i=0}^{n-1}f\_i\bigl((q-1)t\_{i+1}-(q-1)t\_i\bigr),$$
then with the notation
$$\tilde t\_i:=[qt\_i]-(q-1)t\_i,\qquad i=0,\dots,n-1,$$
we get
$$\sum\_{j=1}^{q-1}F\left(\frac{j}{q}\right)=\sum\_{i=0}^{n-2}f\_i\bigl(\tilde t\_{i+1}-\tilde t\_i\bigr)-f\_{n-1}\tilde t\_{n-1}=\sum\_{i=1}^{n-1}(f\_{i-1}-f\_i)\tilde t\_i.$$
By (1) we can write $(q-1)t\_i=n\_i+e\_i$ with $n\_i\in\mathbb{Z}$ and $|e\_i|<\epsilon$. Then
$$qt\_i = n\_i+t\_i+e\_i,\qquad i=1,\dots,n-1,$$
whence by (2), that is by $\epsilon<\min(t\_1,1-t\_{n-1})$, we have
$[qt\_i]=n\_i$, so that $\tilde t\_i=-e\_i$. It follows that
$$\sum\_{j=1}^{q-1}F\left(\frac{j}{q}\right)=\sum\_{i=1}^{n-1}(f\_i-f\_{i-1})e\_i,$$
whence
$$\left|\sum\_{j=1}^{q-1}F\left(\frac{j}{q}\right)\right|<\epsilon\sum\_{i=1}^{n-1}|f\_i-f\_{i-1}|.$$
The right hand side can be made arbitrary small, so we are done.


