提交时间:2022-10-15 11:34:23

运行 ID: 60432

#include <iostream> #include <map> #include <cstdio> using namespace std; const int N = 100010; int a[N],m; map<long long,map<int,long long> >f; long long DFS(int x,long long ti) { //cout<<x<<' '<<ti<<' '<<f[x][ti]<<endl; if(f[x][ti]) return f[x][ti]; if(x == m + 1) return f[x][ti] = ti; return f[x][ti] = DFS(x + 1,(ti % a[x] == 0?ti:(ti / a[x] + 1) * a[x])); } int main() { //freopen("S2.in","r",stdin); //freopen("S2.out","w",stdout); int n,i; cin>>n>>m; for(i = 1;i <= m;i++) cin>>a[i]; for(i = 1;i <= n;i++) cout<<DFS(1,i)<<' '; cout<<endl; return 0; }