Consider the following code, taken from Alain Matthes' answer here.
Code
\documentclass{article}
\usepackage{tikz}
\makeatletter
\pgfutil@ifundefined{pgfmath@function@isprime}{%
\newif\ifpgf@unknown
\newif\ifpgf@isaprime
\pgfmathdeclarefunction{isprime}{1}{%
\begingroup%
\pgf@unknowntrue
\c@pgfmath@counta#1\relax%
\ifcase#1\relax
% |#1| = 0
\pgf@isaprimefalse\pgf@unknownfalse
\or
% |#1| = 1
\pgf@isaprimefalse\pgf@unknownfalse
\or
% |#1| = 2
\pgf@isaprimetrue\pgf@unknownfalse
\or
% |#1| = 3
\pgf@isaprimetrue\pgf@unknownfalse
\else
% |#1| > 3
\ifodd#1\relax
\else
\pgf@isaprimefalse\pgf@unknownfalse
\fi
\fi
\ifpgf@unknown
\c@pgfmath@countd=\thr@@ \pgf@isaprimetrue
\loop
\c@pgfmath@countb=\c@pgfmath@counta
\divide\c@pgfmath@countb by\c@pgfmath@countd
\ifnum\c@pgfmath@countb>\c@pgfmath@countd \pgf@unknowntrue
\else\pgf@unknownfalse\fi
\multiply\c@pgfmath@countb by\c@pgfmath@countd
\ifnum\c@pgfmath@countb=\c@pgfmath@counta
\global\pgf@isaprimefalse\pgf@unknownfalse\fi
\ifpgf@unknown\advance\c@pgfmath@countd by 2\relax%
\repeat
\fi
\ifpgf@isaprime
\def\pgfmathresult{1}%
\else
\def\pgfmathresult{0}%
\fi
\pgfmath@smuggleone\pgfmathresult%
\endgroup
}}{}
\makeatother
\begin{document}
\def\scaling{0.5}
\begin{tikzpicture}[y=-1cm,scale=\scaling]
\foreach \x in {0,...,9}
\foreach \y in {1,...,10}
{\draw (\x,\y) +(-0.5cm,-0.5cm) rectangle ++(0.5cm,0.5cm);
\pgfmathtruncatemacro{\nb}{\x*10+\y}
\ifnum\nb=1
\def\pgfmathresult{1}
\else
\node[minimum size=\scaling cm](last) at (\y-1,\x+1) {\nb};
\pgfmathisprime{\nb}
\fi
\ifnum\pgfmathresult=0
\draw[red](last.north west)--(last.south east)
(last.north east)--(last.south west);
\fi}
\end{tikzpicture}
\end{document}
Output

Question
How do I draw the red lines correct when scaling the picture? If I use
\def\scaling{1}
everything is okay, but with
\def\scaling{0.5}
(as in the picture), the lines are not drawn from, and to, the corners of the squares.
P.S. I don't know TikZ at all, so the problem is probably a trivial mistake by me.


:)Thanks for the initial code! – Svend Tveskæg May 05 '13 at 09:01