結果
| 問題 |
No.546 オンリー・ワン
|
| コンテスト | |
| ユーザー |
nxteru
|
| 提出日時 | 2018-10-28 18:36:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 920 bytes |
| コンパイル時間 | 777 ms |
| コンパイル使用メモリ | 82,868 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-19 07:12:44 |
| 合計ジャッジ時間 | 1,501 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,l,r,a[15];
ll gcd(ll x,ll y){
if(x<y)swap(x,y);
if(x%y==0)return y;
return gcd(y,x%y);
}
ll lca(ll x,ll y){
return x*y/gcd(x,y);
}
ll sum(ll x){
ll res=0;
for(int k=1;k<1<<n;k++){
ll p=1,c=0;
bool ok=true;
for(int i=0;i<n&&ok;i++){
if(k>>i&1){
p=lca(p,a[i]);
if(p>x)ok=false;
c++;
}
}
if(!ok)continue;
if(c==1)res+=x/p;
else if(c%2)res+=(x/p)*c;
else res-=(x/p)*c;
}
return res;
}
int main(void){
cin>>n>>l>>r;
for(int i=0;i<n;i++)cin>>a[i];
cout<<sum(r)-sum(l-1)<<endl;
}
nxteru