Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. using namespace std;
  4.  
  5. int a[1007];
  6. vector<int> v;
  7.  
  8. void solve() {
  9.     int b,n;
  10.     cin>>b>>n;
  11.     for(int i=0;i<b;i++) cin>>a[i];
  12.     if(n <= b) {
  13.         cout<<n<<"\n";
  14.     }
  15.     else {
  16.         v.clear();
  17.         int mx=-1;
  18.         n-=b;
  19.         int sz=0;
  20.         for(int i=0;i<b;i++) mx=max(mx,a[i]);
  21.         for(int tm=1;tm<=1000;tm++) {
  22.             for(int i=0;i<b;i++) {
  23.                 if(tm%a[i]==0) {
  24.                     v.pb(i+1);
  25.                     sz++;
  26.                 }
  27.             }
  28.         }
  29.         n %= sz;
  30.         cout<<v[(n+sz-1) % sz]<<"\n";
  31.     }
  32. }
  33.  
  34. int main() {
  35.     int t; cin>>t;
  36.     for(int qq=1;qq<=t;qq++) {
  37.         cout<<"Case #"<<qq<<": ";
  38.         solve();
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement