이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define foxr1(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
int n, q, x, t, l2, k, lo=(1 << 30), dp[10000005], f[10000005];
vector<bool> p=vector<bool>(10000005);
int main(){
scanf("%i%i", &n, &q);
fox(l, n){
scanf("%i", &x);
p[x]=1;
lo=min(lo, 10000000/x*x);
}
for(int l=2; l<=10000000; l++){
if (f[l]!=0) continue;
if (p[l]) k=l; else k=-1;
if (k==-1){
if (l>10000) continue;
l2=l*l;
} else l2=l;
for (; l2<=10000000; l2+=l){
f[l2]=k;
}
}
foxr1(l, 10000000){
t=lo;
lo=min(lo, l-max(0, f[l]));
f[l]=t;
//cout << f[l] << endl;
}
fox1(l, 10000000){
if (f[l]==l) dp[l]=(1 << 30);
dp[l]=dp[f[l]]+1;
}
fox(l, q){
scanf("%i", &x);
if (dp[x]>=(1 << 30)){
printf("oo\n");
}
else {
printf("%i\n", dp[x]);
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &q);
^
brunhilda.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &x);
^
brunhilda.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &x);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |