CSES - Datatähti 2019 alku - Results
Submission details
Task:Ruudukko
Sender:PekaaniP
Submission time:2018-10-13 22:09:31 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'double f(double)':
input/code.cpp:14:12: error: invalid operands of types 'double' and 'double' to binary 'operator%'
         a=a%mod;
           ~^~~~
input/code.cpp: In function 'int main()':
input/code.cpp:45:12: error: invalid operands of types 'double' and 'double' to binary 'operator%'
         a=a%mod;
           ~^~~~
input/code.cpp:49:19: error: invalid operands of types 'double' and 'int' to binary 'operator%'
     std::cout << a%(1000000007);
                  ~^~~~~~~~~~~~~
input/code.cpp:35:12: warning: unused variable 'm' [-Wunused-variable]
     double m=0;
            ^

Code

#include <iostream>
#include <cmath>


double mod=1000000007;

double f(double n){
    int i=1;
    if(n==0){return 1;}
    double a=1;
    while(i <= n){
        a*=i;
        i++;
        a=a%mod;
    }
    return a;
}
double nk(double n, double k){
    if(n==k){return 1;}
    return (f(n)/(f(k)*f(n-k)));
}
double nksum(double i, double n){
    int a=0;
    double c=i;
    while(i<n){
        a+=nk(i,c);
        i++;
    }
    return a;

}
int main() {
    double i=0;
    double n;
    double m=0;
    double a;
    double k;
    std::cin >> n;
    a=1;
a=0;
    for(k=0; k<=n;k++){
        i=f(k)*pow(-1,n-k)*nk(n,k);
        i*=f(n);
        a+=i;
        a=a%mod;
    }


    std::cout << a%(1000000007);
}