Submission #172488


Source Code Expand

Copy
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

// 最大公約数
int gcd(int a, int b){
    while(b != 0){
        int tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}


int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    map<int, long long> dp, ret;
    for(int i=0; i<n; ++i){
        map<int, long long> nextDp;
        nextDp[a[i]] = 1;
        for(const auto& p : dp)
            nextDp[gcd(p.first, a[i])] += p.second;
        for(const auto& p : nextDp)
            ret[p.first] += p.second;
        dp.swap(nextDp);
    }

    for(int i=0; i<m; ++i){
        int x;
        cin >> x;
        cout << ret[x] << endl;
    }

    return 0;
}

Submission Info

Submission Time
Task D - GCD区間
User mamekin
Language C++ (G++ 4.6.4)
Score 0
Code Size 1112 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:45:25: error: ISO C++ forbids declaration of ‘p’ with no type [-fpermissive]
./Main.cpp:45:29: error: range-based-for loops are not allowed in C++98 mode
./Main.cpp:46:26: error: request for member ‘first’ in ‘p’, which is of non-class type ‘const int’
./Main.cpp:46:45: error: request for member ‘second’ in ‘p’, which is of non-class type ‘const int’
./Main.cpp:47:25: error: ISO C++ forbids declaration of ‘p’ with no type [-fpermissive]
./Main.cpp:47:29: error: range-based-for loops are not allowed in C++98 mode
./Main.cpp:48:19: error: request for member ‘first’ in ‘p’, which is of non-class type ‘const int’
./Main.cpp:48:31: error: request for member ‘second’ in ‘p’, which is of non-class type ‘const int’