Created
October 27, 2017 22:11
-
-
Save IvanIsCoding/f22070f1a6b1812077331ba9fa370e90 to your computer and use it in GitHub Desktop.
Seletiva IOI 2014
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ivan Carvalho | |
| // Risco - Seletiva IOI - OBI 2014 | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int gcd(int a,int b){ | |
| if(a < b) swap(a,b); | |
| if(b == 0) return a; | |
| return gcd(b,a%b); | |
| } | |
| int main(){ | |
| long long resp = 0; | |
| int n,L,R; | |
| scanf("%d %d %d",&n,&L,&R); | |
| map<int,int> velho,novo; | |
| map<int,long long> grande; | |
| for(int i=1;i<=n;i++){ | |
| novo.clear(); | |
| velho[0]++; | |
| int x; | |
| scanf("%d",&x); | |
| for(map<int,int>::iterator it = velho.begin();it != velho.end();it++){ | |
| int y = (*it).first; | |
| int qtd = (*it).second; | |
| int mdc = gcd(x,y); | |
| if(mdc <= L){ | |
| resp += 1LL*(R - L + 1)*qtd; | |
| } | |
| else if(L <= mdc && mdc <= R){ | |
| resp += 1LL*(R - mdc + 1)*qtd; | |
| } | |
| novo[mdc] += qtd; | |
| } | |
| velho = novo; | |
| } | |
| printf("%lld\n",resp); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment