結果

問題 No.546 オンリー・ワン
ユーザー nxterunxteru
提出日時 2018-10-28 18:31:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 860 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 82,868 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-29 22:30:52
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
		for(int i=0;i<n;i++){
			if(k>>i&1){
				p=lca(p,a[i]);
				c++;
			}
		}
		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;
}
0