Topic Requirements: Enter n, calculate s = 1! +2! +3! +...n! The last 6 bits, n<=10^6
Example input: 10
Sample output: 37913
Source:
1#include <stdio.h>2#include <time.h>3 4 intMain ()5 {6 //const int MOD = 1000000;7 intI,j,n,s =0;8scanf"%d",&n);9 for(i =1; I <= n;i++)Ten { One intfactorial =1; A for(j =1; J <= i;j++) -Factorial = (factorial *j); -s = (s +factorial); the } -printf"%d\n", s%1000000); -printf"Time =%.21f\n",(Double) clock ()/clocks_per_sec); - return 0; +}
This is the summation and then the modulo.
If the gradual modulo is summed again, the following:
1#include <stdio.h>2#include <time.h>3 4 intMain ()5 {6 Const intMOD =1000000;7 intI,j,n,s =0;8scanf"%d",&n);9 for(i =1; I <= n;i++)Ten { One intfactorial =1; A for(j =1; J <= i;j++) -Factorial = (factorial * J%MOD); -s = (s + factorial)%MOD; the } -printf"%d\n", s); -printf"Time =%.21f\n",(Double) clock ()/clocks_per_sec); - return 0; +}
The first paragraph, the small number can be, input 100 multiplication overflow
The second big number can also be, that is, the number of large-size program to run too long time;
Example 2-3 the sum of factorial