P16869 [HackerEarth] Steave has abundant N types of coins.He went to a shop where price of each product was unique.Luckily the shopkeeper was his friend.He tells Steave that they are selling products in some
提高-
题目描述

Steave has abundant N types of coins.He went to a shop where price of each product was unique.Luckily the shopkeeper was his friend.He tells Steave that they are selling products in some price range [P,Q] everyday.
He also tells Steave that for every price, there is a product in the shop but policy was that Customer may only use a single type of coin for each product which he purchases.
For example, he could pay for a product of price 6 with two 3-coins, but not with a 2-coin and a 4-coin.
So you need to tell how many different types of products he can buy.

Input Format:

The first line of input contains N, the number of types of coins Steave has.
Then the next N lines contain an integer each: the ith line contains A[i], the value of Steave's ith type of coin.

Then the next line contains a number T,number of test cases.
Then each of the next T lines contains numbers P and Q, denoting that they are selling items in price range [P,Q].

Output format:

There will be T lines, each containing the number of distinct items that can be bought in that particular range.

Constraints:

1 ≤N ≤ 20
1 ≤ A[i]≤ 60
1 ≤ T ≤101
1 ≤ P ≤ Q ≤ 10^18

SAMPLE INPUT
4
2
3
4
5
3
1 10
2 20
3 7

SAMPLE OUTPUT
8
14
4

Explanation

For Case 1: He can buy items of price {2,3,4,5,6,8,9,10},so total number of products are 8.
For Case 2: He can buy items of price {2,3,4,5,6,8,9,10,12,14,15,16,18,20} so total 14 products.
For Case 3: He can buy items of price {3,4,5,6},so total 4 products.

输入格式

见题面

输出格式

见题面

样例输入
17 6 35 50 2 50 35 48 4 50 20 37 35 1 18 15 5 40 100 64799987271847768 680348850883916111 91666590415702617 351216839133230010 185635158752598761 348487420896786159 462046743146025358 894157930340797251 364607088680642241 458090865282748403 357843059554915782 919786101929199986 117269771807409875 180650019656295635 435414464942545681 734207976792109973 40442667481473361 191826531941565748 366581061153437341 396542247248322744 578130756926314282 654903820285058583 5356398800564492 367350656139309616 64713027041425922 113719103888747381 205972144605355825 301271511942447591 512554602908666120 529471436198120394 468375919105527440 597925719680519879 182979643527381440 560898022561405565 122311847763530484 456588890550358136 100060990792820646 640149874842384871 39760070941626120 71531061991223529 153588311356631601 749475415003632674 744992515067099343 888294591521205868 28222894238136247 943617197361661753 340641541861322312 389317343764777898 109475872312829747 993205149409389816 700897297538757897 953305332365062849 112457334954629 257506103026693 128586905785554794 875161340661422606 192120096597774614 393516553651445485 334779225565658902 774396961881468030 560374633939791938 903484442999118028 221111098035734112 575283208640210411 171864642383205682 375967264486332081 148354551109542283 226272497608441218 362287326751719301 817127862063738998 266581000818081683 903745913842945519 625881308576861194 872755953114668412 6725494474027379 329049313519841829 161019796381005301 369759976255990092 148724097316396229 199282859813089946 285362989841338 519859090724992753 39648608051638415 637841692255387068 894677239499868068 951163574023321621 873525015955158932 946575042356763189 468524210280959104 786755430305183436 53433924484419525 390712719976929365 675144635785658015 916530307311307580 675529382082285777 811776733459706994 149111558929279570 496079596852095562 116592669210879662 561896562668809786 753950666274957376 858876822328591709 59235285177382585 919657300181977120 378032787913609778 489307554479446947 309798701460851994 313046781868785842 683904643110181851 768364797999155519 786194360100012003 788397416092591955 644811342300823194 656641926971120783 119970369139911563 622065475016450473 887621737182791376 949727600821106828 420992788233833680 816131994512271862 424657259194645352 573583431749496541 630614773651081828 905511774826983675 21471498709367776 154994801995153968 124187539050433433 864601722363752711 148452044876556872 446479912062152290 92105643156283396 849590466630987429 446556128828686111 545810646129112519 44435190335066261 66949237308621723 304483245415364438 489896460838421429 93795517172103832 154843543820754137 136585283178678215 341524414947847174 298285266201638059 317569553603549777 184909921133565211 414623520284658447 305750232973337079 764368592053366659 35078527246931966 302833754409244540 670358723236875810 751465592347139587 314610123693009604 435319920152642952 525389500577429138 881318057219421792 113362324167775914 701122812054376714 288642605955468911 843132570728841349 31471976019733128 143100165050549636 29850526227299198 53880921230166323 310915627177881407 352637550577805863 24156137645168636 29967302110288956 8014702688602923 34283660312908826 832154171043462741 953738505645131611 346932735276834 395954916968808 16714587589310425 33089509753479312 319569647750784692 840178148326317491 779300997594566532 856402263776324843 226186033422367 129836031404641218 323762424944577922 663945195134727758 25717677316029204 349395862008782058 72059141240250571 126481287846929006 134192956824375254 209809890475682687 10520379519511441 477942105184220080 525723595196590511 605324005150468553 90401687048925977 233405676032334440 255695627697053960 283877768724887880 642513346663996274 939350645623693347
样例输出
39213412113716225 201955208088948420 379860913904327214 145256059789708305 35107150330966150 332322230416303696 44010989640915946 615225174224165492 8745059322094215 21693765787527143 127802354530245225 205265602996109024 493487162784931273 188163547026905632 119523397434656482 354027927515306967 4224795024601776 625340309738609486 475324348347972737 81889958783573334 471372367722912740 72175574941563439 260138112188859954 128514256168681986 431649798902785815 602827671680726560 94993634768607525 290668490572507756 218397318543425606 2646895827719059 559158068906562916 2657730173490131 1370754763846863 8809996385291182 124281113836406846 72768343455501400 2015054359132892 346089337378372059 91008253646085108 290363180254460802 215145226649311926 62362610512355909 158283980775039209 647268872660961911 656182788317093517 15867523371581284 180279180289869451 203110186036708307 416263751740424695 5886124248131172 312563756958342974 207778846012767085 273327668307112633 25966391382773935 232326356434777273 155364811125470264 96335784979605790 236949933512324056 484668336011184405 271903047023730403 706676715197463571 148569753528521084 106931059830388482 328833343796382127 63454974162553340 126531809277725492 77053351120186959 659876680142429911 150767274515377735 153134603439705896 97402115484491605 814179079554190439 118794665671532657 52497396421092614 1387826119403084 1055905221096940 31295678882004246 90320283636921064 202682200887318013 746325599543508837 110817235353574861 634926992919731644 82162176181961440 176785121992764967 62219261260391285 18031347618242318 432404918253723638 433833916935275391 504643063410995188 76400065178375130 585983000710160726 98162114061288399 9621951704719948 484080707658226 346616301183835313 967978383973772292 118325836325198020 181887176494238915 38068282261898381 55819365252358883