Skip to content

Commit 2198b43

Browse files
Merge pull request #755 from ask2sm/patch-24
Add exchangemoney.cpp
2 parents 72b88b4 + 3fbf7e9 commit 2198b43

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

exchangingmoney.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//hackerearth problem picked from noveasy19
2+
//Problem url:https://www.hackerearth.com/problem/algorithm/money-exchange-48c4a575/
3+
4+
/*question:There are n types of money denomination in your country having values a1,a2,..an .
5+
You went to a shop to buy a product worth p units,
6+
predict whether is it possible to complete the purchase or not
7+
(You and the shopkeeper can choose notes of each denomination any number of times).
8+
You need to process Q queries for this.
9+
Print "YES" if it is possible to complete the purchase,
10+
else print "NO".*/
11+
12+
//Program
13+
#include<bits/stdc++.h>
14+
15+
using naemespace std;
16+
17+
#define llt long long int
18+
int main()
19+
{
20+
llt t n,q;
21+
cin>>n>>q;
22+
//long long int type
23+
llt a[n],g=0;
24+
for(llt i=0;i<n;i++)
25+
{
26+
cin>>a[i];
27+
//__gcd is inbuild funtion in cpp to calculate gcd of two numbers
28+
g=__gcd(a[i],g);
29+
}
30+
31+
//q number of query
32+
33+
while(q--)
34+
{
35+
llt p;
36+
cin>>p;
37+
if(__gcd(g,p)==g)
38+
cout<<"YES"<<endl;
39+
else
40+
cout<<"NO"<<endl;
41+
}
42+
43+
}
44+
45+
/*
46+
Input:
47+
2 2
48+
6 9
49+
3
50+
4
51+
Output:
52+
YES
53+
NO
54+
55+
Note:For the first query p=3 , you give a note of 9 to the salesman and he returns 6 to you,
56+
hence the purchase completed successfully.
57+
*/

0 commit comments

Comments
 (0)