Project Euler #31: Coin sums

  • + 0 comments

    Cpp code C++20

    include

    include

    include

    include

    include

    using namespace std;

    long long modulo=pow(10,9)+7;

    int ceil(int a, int b){ a+= (a%b) ?b-a%b :0;
    return a/b; } int main() { int t; cin>>t;

    vector<int> numbers{5,10,20,50,100,200};
    
    int n=pow(10,5);
    
    long long answers[n+1];
    
    for (int i=0; i<n+1; i++){
        answers[i]=ceil(i+1,2);
    }
    
    for (int i: numbers){
        for (int j=i; j<n+1; j++){
            answers[j]+=answers[j-i];
            answers[j]%=modulo;
        }
    }
    
    
    while (t--){
        cin>>n;
    
        cout<<answers[n]<<endl;
    }
    return 0;
    

    }