# General accumulation

You can obtain an even more general version of `accumulate` (exercise 1.32 ) by introducing the notion of a filter on the terms to be combined. That is, combine only those terms derived from values in the range that satisfy a specified condition. The resulting `filtered-accumulate` abstraction takes the same arguments as `accumulate` , together with an additional predicate of one argument that specifies the filter. Write `filtered-accumulate` as a procedure. Show how to express the following using `filtered-accumulate` :

a. the sum of the squares of the prime numbers in the interval `a` to `b` (assuming that you have a `prime?` predicate already written)

b. the product of all the positive integers less than `n` that are relatively prime to `n` (i.e., all positive integers `i < n` such that GCD `(i, n) = 1` ).

##### Authentication required

``````(define (inc n) (+ n 1))
{"ft_lang_label":"__label__en","ft_lang_prob":0.7589929,"math_prob":0.9327776,"size":1181,"snap":"2021-43-2021-49","text_gpt3_token_len":302,"char_repetition_ratio":0.14188614,"word_repetition_ratio":0.0,"special_character_ratio":0.24978831,"punctuation_ratio":0.10666667,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99059916,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-18T04:26:45Z\",\"WARC-Record-ID\":\"<urn:uuid:b4651e61-ae8a-446e-b2b5-759e1ad435ac>\",\"Content-Length\":\"21163\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c0371a6c-3dbf-4313-8851-ce7d24de829b>\",\"WARC-Concurrent-To\":\"<urn:uuid:d84659c4-179f-4e50-9bcf-a9ab7569a5d6>\",\"WARC-IP-Address\":\"52.212.52.84\",\"WARC-Target-URI\":\"https://sicp.hexlet.io/exercises/33\",\"WARC-Payload-Digest\":\"sha1:MQKN264CGUHKENSSQ5EJP72MYLSWRODQ\",\"WARC-Block-Digest\":\"sha1:IGUFHKAX3C63WUZSLZWSTJL4MZ62QDY6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585196.73_warc_CC-MAIN-20211018031901-20211018061901-00378.warc.gz\"}"}