由于使用科学计数法而导致的错误

时间:2019-06-29 05:46:25

标签: c++

我尝试了一个Hackerearth教程question,并能够使用以下代码正确解决它:

    #include <iostream>
    using namespace std;
    int main() {
        const long int MOD = 1000000007;
        const long int SIZE = 100001;
        long int t, n;
        long int cache[SIZE];

        cache[0] = 1;

        for (long int i = 1; i < SIZE; i++) {
            cache[i] = ( i * cache[i-1] ) % MOD;
        }

        cin >> t;
        while (t--) {
            cin >> n;
            cout << cache[n] << endl;
        }

        return 0;
    }

但是,当使用科学计数法来编写MOD或SIZE时,在线法官会报告错误的答案。我在这里想念什么?

    #include <iostream>
    using namespace std;
    int main() {
        const long int MOD = 10e9+7;
        const long int SIZE = 100001;
        long int t, n;
        long int cache[SIZE];

        cache[0] = 1;

        for (long int i = 1; i < SIZE; i++) {
            cache[i] = ( i * cache[i-1] ) % MOD;
        }

        cin >> t;
        while (t--) {
            cin >> n;
            cout << cache[n] << endl;
        }

        return 0;
    }

1 个答案:

答案 0 :(得分:1)

科学符号表示“常数乘以10乘以x的幂”。如果需要1000000007,则需要1e9,意思是“一个后跟九个零”。现在使用10e9,即“十后跟九个零”或“一个后十个零”。所以您的假期减少了十倍。