結果
問題 | No.546 オンリー・ワン |
ユーザー |
|
提出日時 | 2020-07-25 03:01:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 3,061 ms |
コンパイル使用メモリ | 194,628 KB |
最終ジャッジ日時 | 2025-01-12 05:13:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:23:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | lint l,r; scanf("%d%lld%lld",&n,&l,&r); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:25:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | rep(i,n) scanf("%lld",&a[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; inline int popcount(int x){ x=((x>>1)&0x55555555)+(x&0x55555555); x=((x>>2)&0x33333333)+(x&0x33333333); x=((x>>4)+x)&0x0f0f0f0f; x+=(x>>8); x+=(x>>16); return x&0x3f; } int main(){ int choose[11][11]={}; rep(i,11) choose[i][0]=1; rep(i,10) rep(j,i+1) choose[i+1][j+1]=choose[i][j]+choose[i][j+1]; int n; lint l,r; scanf("%d%lld%lld",&n,&l,&r); vector<lint> a(n); rep(i,n) scanf("%lld",&a[i]); int coef[11]; for(int i=2;i<=n;i++){ coef[i]=i; for(int j=2;j<i;j++) coef[i]-=choose[i][j]*coef[j]; } lint ans=0; rep(S,1<<n) if(S!=0) { lint L=1; rep(i,n) if(S>>i&1) L=min(lcm(L,a[i]),r+1); int pc=popcount(S); if(pc==1){ ans+=r/L-(l-1)/L; } else{ ans-=coef[pc]*(r/L-(l-1)/L); } } printf("%lld\n",ans); return 0; }