File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments