QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707058#6566. Power of Divisorstassei903#WA 27ms7092kbC++232.9kb2024-11-03 14:32:152024-11-03 14:32:17

Judging History

你现在查看的是最新测评结果

  • [2024-11-03 14:32:17]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:7092kb
  • [2024-11-03 14:32:15]
  • 提交

answer


#include <bits/stdc++.h>
#include <bits/extc++.h> 
using namespace std;
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = l; i < (r); i++)
#define all(x) begin(x), end(x)

using ll = long long;
using vi = vector<int>;

const ll INF = numeric_limits<ll>::max() / 100;

struct MCMF{

	struct edge {
		int from, to, rev;
		ll cap, cost, flow;
	};

	int N;
	vector<vector<edge>> ed;
	vi seen;
	vector<ll> dist, pi;
	vector<edge*> par;

	MCMF(int N) : N(N), ed(N), seen(N), dist(N), pi(N), par(N) {}

	void addEdge(int from, int to, ll cap, ll cost) {
		if (from == to) return;
		ed[from].push_back(edge{ from, to, sz(ed[to]), cap, cost, 0});
		ed[to].push_back(edge{to, from, sz(ed[from])-1, 0, -cost, 0});
	}

	void path(int s) {
		fill(all(seen), 0);
		fill(all(dist), INF);
		dist[s] = 0; ll di;

		__gnu_pbds::priority_queue<pair<ll, int>> q;
		vector<decltype(q)::point_iterator> its(N);
		q.push({0, s});
		while (!q.empty()) {
			s = q.top().second; q.pop();
			seen[s] = 1; di = dist[s] + pi[s];
			for (edge& e : ed[s]) if (!seen[e.to]) {
				ll val = di - pi[e.to] + e.cost;
				if (e.cap - e.flow > 0 && val < dist[e.to]) {
					dist[e.to] = val;
					par[e.to] = &e;
					if (its[e.to] == q.end()) {
						its[e.to] = q.push({-dist[e.to], e.to});
					}
					else {
						q.modify(its[e.to], {-dist[e.to], e.to});
					}
				}
			}
		}

		rep(i,0,N) pi[i] = min(pi[i] + dist[i], INF);
	}

	pair<ll, ll> maxflow(int s, int t) {
		ll totflow = 0, totcost = 0;
		while (path(s), seen[t]) {
			ll fl = INF;
			for (edge* x = par[t]; x; x = par[x->from]) {
				fl = min(fl, x->cap - x->flow);
			}

			totflow += fl;
			for(edge* x = par[t]; x; x = par[x->from]) {
				x->flow += fl;
				ed[x->to][x->rev].flow -= fl;
			}
		}

		rep(i, 0, N)for(edge& e : ed[i]) totcost += e.cost * e.flow;
		return {totflow, totcost/2};
	}
};

bool is_prime(ll x) {
    for (ll a = 2; a * a <= x; a++) {
        if (x % a == 0)return 0;
    }
    return 1;
}

const ll inf = 1e18 + 2;
ll safe_pow(ll x, int e) {
    ll a = 1;
    rep(_, 0, e) {
        if (a >= (inf-1) / x + 1)return -1;
        a *= x;
    }
    return a;
}

int N = 1000000;
int main() {
    ll n;cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll ok = 0, ng = 1e9+7;
    while (ng - ok > 1) {
        ll mid = ok + ng >> 1;
        if (mid * mid <= n) {
            ok = mid;
        }
        else { 
            ng = mid;
        }
    }

    if (ok * ok == n && is_prime(ok)) {
        cout << ok << endl;
        return 0;
    }

    vector<int> d(N, 0);
    rep(i, 1, N) {
        for (int j = i; j < N; j += i) {
            d[j]++;
        }

        ll x = safe_pow(i, d[i]);
        if (x == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 6928kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

score: 0
Accepted
time: 5ms
memory: 7048kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 27ms
memory: 7092kb

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 22ms
memory: 6916kb

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 23ms
memory: 7004kb

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 6908kb

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Wrong Answer
time: 27ms
memory: 7052kb

input:

1000000000000000000

output:

-1

result:

wrong answer 1st lines differ - expected: '100', found: '-1'