可以使用一些方法控制小數點後的位數要輸出多少,以下以輸出 n
到小數點後 10 位為例
使用 cout:cout << fixed << setprecision(10) << n;
使用 printf:printf("%.10lf", n);
使用 python:print('%.10f' % n)
P.S. cout 要 #include <iomanip>
可以使用一些方法控制小數點後的位數要輸出多少,以下以輸出 n
到小數點後 10 位為例
使用 cout:cout << fixed << setprecision(10) << n;
使用 printf:printf("%.10lf", n);
使用 python:print('%.10f' % n)
P.S. cout 要 #include <iomanip>
你們可能會需要這個定理來防止算術溢位:
若 $\begin{cases}a \equiv b \mod p \\ c \equiv d \mod p \end{cases}$ 則 $a+c \equiv b+d \mod p$