Gun's Blog

计蒜客

Word count: 99Reading time: 1 min
2019/09/22 Share

An Olympian Math Problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
using namespace std;
int factorial(int k);
int modulo(int s,int n);
int main()
{
int t;
cin>>t;
while(t--)
{
long n;
cin>>n;
int sum=0;
for(int i=1;i<n;i++)
{
sum+=i*factorial(i);
}
cout<<modulo(sum,n)<<endl;
}
return 0;
}
int factorial(int k)
{
if(k==1)
return 1;
else{
return k*factorial(k-1);
}
}
int modulo(int s,int n)
{
return s%n;
}
CATALOG
  1. 1. An Olympian Math Problem