Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- using namespace std;
- int a[1007];
- vector<int> v;
- void solve() {
- int b,n;
- cin>>b>>n;
- for(int i=0;i<b;i++) cin>>a[i];
- if(n <= b) {
- cout<<n<<"\n";
- }
- else {
- v.clear();
- int mx=-1;
- n-=b;
- int sz=0;
- for(int i=0;i<b;i++) mx=max(mx,a[i]);
- for(int tm=1;tm<=1000;tm++) {
- for(int i=0;i<b;i++) {
- if(tm%a[i]==0) {
- v.pb(i+1);
- sz++;
- }
- }
- }
- n %= sz;
- cout<<v[(n+sz-1) % sz]<<"\n";
- }
- }
- int main() {
- int t; cin>>t;
- for(int qq=1;qq<=t;qq++) {
- cout<<"Case #"<<qq<<": ";
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement