?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
108382536 |
Practice: Manas_Rocko |
1492A - 85 | C++17 (GCC 7-32) | Accepted | 31 ms | 8 KB | 2021-02-24 12:45:05 | 2021-02-24 12:45:05 |
#include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include<bits/stdc++.h> using namespace std; using namespace __gnu_pbds; #define int long long #define fl(i,n) for(int i=0;i<n;i++) #define v(i) vector<int> #define um unordered_map<int,int> #define pb push_back #define pr pair<int,int> #define NO cout<<"NO"; #define all(a) a.begin(),a.end() #define YES cout<<"YES"; #define sortn(a) sort(a.begin(),a.end()) #define sortc(a,cp) sort(a.begin(),a.end(),cp) #define pq priority_queue<int> #define vvi vector<v(i)> #define reverse(a) reverse(a.begin(),a.end()) #define mp make_pair /* lcm(a,b) , _gcd(a,b) , swap(a,b) , sort(a.begin(),a.end()) , *max_element(a.begin(),a.end()) , *min_element(a.begin(),a.end()) */ /* _builtin_popcount(x): This function is used to count the number of one’s */ /*__builtin_clz(x): This function is used to count the leading zeros of the integer. */ /* string s.find("ks")==string::npos if not found */ /*__builtin_ctz(x): This function is used to count the trailing zeros of the given integer */ /* binary_search(a, a + 10, 10) -> true/false */ /* this creates a sorted set with func in log time *p.find_by_order(x) , p.order_of_key(x) if not present than its pos in sorted array*/ /* cout<<fixed<<setprecision(8) , round(1.589) -> 2 , trunc(1.590) -> 1 , ceil(x) , floor(x) */ /* // using merge() to merge the initial containers merge(arr1.begin(), arr1.end(), arr2.begin(), arr2.end(), arr3.begin()); */ // int mult(int x,v(i) &arr,int s){ // int c=0; // fl(i,s){ // int p=arr[i]*x+c; // arr[i]=p%10; // c=p/10; // } // while(c){ // arr[s]=c%10; // c=c/10; // s++; // } // return s; // } // string fact(int k){ // v(i) arr(50000); // arr[0]=1; // int size=1; // for(int x=2;x<=k;x++){ // size=mult(x,arr,size); // } // string s=""; // int j=0; // for(int i=size-1;i>=0;i--){ // char c= arr[i] ; // // cout<<arr[i]; // s+=(c+'0'); // } // return (s); // } void SieveOfEratosthenes(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } for (int p=2; p<=n; p++) if (prime[p]) cout << p << " "; } int power(int x, int y, int m) { if (y == 0) return 1; int p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /* inverse of y is power(y,p-2,p) */ /* int fct(int n,int st){ int ans=0; int last=1; int i=st; if(n%i==0){ int c=0; while(n%i==0 && (n/i)%i==0){ n=n/i; c++; } ans+=c; } if(n>1) ans++; return ans; } vector<int> fctr(int n,int i){ vector<int> ans; int last=1; { if(n%i==0){ int c=0; while(n%i==0 && (n/i)%i==0){ n=n/i; c++; ans.pb(i); } } } if(n>1) ans.pb(n); return ans; } */ // int binsearch(v(i) a,int x){ // int l=0,r=a.size()-1; // while(l<=r){ // int m=(l+r)/2; // if(a[m]==x) return m; // else if(a[m]>x) r=m-1; // else l=m+1; // } // return -1; // } void print(v(i) a){ fl(i,a.size()) cout<<a[i]<<" "; cout<<"\n"; } int gcd( int a, int b) { if (b == 0) return a; return gcd(b, a % b); } // Function to return LCM of two numbers int lcm(int a, int b) { return (a / gcd(a, b)) * b; } bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; bool cmp(int a,int b){ return a>b;} int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ int p; v(i) a(3); cin>>p; fl(i,3) cin>>a[i]; int k; fl(i,3){ int c=ceil(double(p)/double(a[i])); if(i) k=min(k,c*a[i]); else k=c*a[i]; } cout<<k-p<<"\n"; } }
?
?
?
?