The key to the study of Deutsch problem lies in constructing Oracle circuit and synthesizing Deutsch circuit. A circuit synthesis algorithm for n-bit Deutsch-Jozsa algorithm is proposed for the first time by using the Cirq framework introduced by Google. The algorithm generates f(x) set randomly according to the number of input quantum wires n, so as to construct Deutsch circuit and simulate it. According to the algorithm, the probability that the set of f(x) generated is a constant function or anequilibrium function is equal. On this basis, the synthesis algorithm is further optimized. The optimized algorithm not only reduces the total number of gates and layers, but also simplifies the structure of the circuit. The simulation speed of the circuit is faster than that before optimization by several times. For example, when n=15, the simulation time after optimization is only 1/6 of that before optimization.