Submission #493686

#TimeUsernameProblemLanguageResultExecution timeMemory
493686SangTinBrunhilda’s Birthday (BOI13_brunhilda)C++14
8.10 / 100
1086 ms53652 KiB
#include <bits/stdc++.h> using namespace std; #define name "TRACKS" #define endl '\n' #define ednl endl #define long long long #define memset(a, x) memset(a, (x), sizeof(a)); #define inoutf freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define IN(a, b, c) (a <= b && b <= c) template<typename T, typename U> inline bool amin(T &x, U y) { if(y >= x) return 0; x = y; return 1;} template<typename T, typename U> inline bool amax(T &x, U y) { if(x >= y) return 0; x = y; return 1;} template<typename T> inline void read(T& x){ bool Neg = false; char c; for (c = getchar(); c < '0' | c > '9'; c = getchar()) if (c == '-') Neg = !Neg; x = c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; if (Neg) x = -x; } const int M = 1e5 + 83, N = 1e7 + 83; int p[M], spf[N], m; bool isPrime[N]; vector <int> Prime; void Sieve(){ memset(isPrime, 1); memset(spf, 0x3f); for (int i = 2; i < N; ++i){ if (isPrime[i]){ Prime.push_back(i); spf[i] = i; } for (int j = 0; j < Prime.size() && 1ll * i * Prime[j] < N && Prime[j] <= spf[i]; ++j){ isPrime[i * Prime[j]] = 0; spf[i * Prime[j]] = Prime[j]; } } } int cal(int n){ if (n < p[m]) return 1; int cur = m, tmp = n; while (cur && tmp % p[cur] == 0){ while (tmp % p[cur] == 0) tmp /= p[cur]; --cur; } return (cur ? (1 + cal(n - n % p[cur])) : -1); } int Solve(){ Sieve(); int q; cin >> m >> q; for (int i = 1; i <= m; ++i){ cin >> p[i]; } sort(p + 1, p + m + 1); while (q--){ int n; cin >> n; int tmp = cal(n); if (tmp == -1) cout << "oo\n"; else cout << tmp << endl; } return 0; } int main(){ fastio; int t = 1; // cin >> t; while (t--){ Solve(); } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'void Sieve()':
brunhilda.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j = 0; j < Prime.size() && 1ll * i * Prime[j] < N && Prime[j] <= spf[i]; ++j){
      |                         ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...