#include #include #include using namespace std; vector suma(vector& v1, vector& v2, int b){ vector sum; int emp=0; while(v1.size()v2.size()){ v2.insert(v2.begin(),0); } for(int i=v1.size()-1; i>=0; i--){ sum.insert(sum.begin(),(v1[i]+v2[i]+emp)%b); emp = (emp + v1[i]+v2[i])/b; } if(emp!=0){ sum.insert(sum.begin(),emp); } return sum; } int mult(vector mult1, vector v2, int b, int m, int n){ if(m==n){ //cout< v3; v3.push_back(1); v2 = suma(v2, v3, b); for(int i=0; i=0; j--){ aux1.insert(aux1.begin(),(v2[1]*mult1[j]+emp)%b); emp = (emp + v2[1]*mult1[j])/b; } if(emp!=0){ aux1.insert(aux1.begin(),emp); } emp=0; aux2.insert(aux2.begin(),0); for(int j=mult1.size()-1; j>=0; j--){ aux2.insert(aux2.begin(),(v2[0]*mult1[j]+emp)%b); emp = (emp + v2[0]*mult1[j])/b; } if(emp!=0){ aux2.insert(aux2.begin(),emp); } mult1 = suma(aux1, aux2, b); for(int i=0; i2){ aux1.clear(); aux2.clear(); emp=0; for(int j=mult1.size()-1; j>=0; j--){ aux1.insert(aux1.begin(),(v2[v2.size()-1]*mult1[j]+emp)%b); emp = (emp + v2[v2.size()-1]*mult1[j])/b; } if(emp!=0){ aux1.insert(aux1.begin(),emp); } emp=0; aux2.insert(aux2.begin(),0); for(int j=mult1.size()-1; j>=0; j--){ aux2.insert(aux2.begin(),(v2[v2.size()-2]*mult1[j]+emp)%b); emp = (emp + v2[v2.size()-2]*mult1[j])/b; } if(emp!=0){ aux2.insert(aux2.begin(),emp); } vector aux3; aux3 = suma(aux1, aux2, b); aux1.clear(); for(int i=2; i=0; j--){ aux1.insert(aux1.begin(),(v2[v2.size()-1-i]*mult1[j]+emp)%b); emp = (emp + v2[v2.size()-1-i]*mult1[j])/b; } if(emp!=0){ aux1.insert(aux1.begin(),emp); } aux3 = suma(aux3, aux1, b); } int comp=0; for(int i=0; i>n; cout<>b; cout< v1; v1.push_back(1); vector v2; v2.push_back(1); mult(v1, v2, b, 1, n); }