QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#851605 | #9619. 乘积,欧拉函数,求和 | xiaodaiyang | WA | 166ms | 4392kb | C++20 | 2.5kb | 2025-01-10 21:02:18 | 2025-01-10 21:02:18 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <random>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <array>
using namespace std;
// #define endl '\n'
typedef long long ll;
#define int long long
typedef __int128_t int128;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
// mt19937 rng(time(0));
mt19937_64 rng(random_device{}());
#define x first
#define y second
#define lowbit(x) ((x) & -(x))
//#define double long double
const int N = 2010, M = 1000010;
ll n, m;
int qmi(int a, int k, int p) {
int res = 1 % p;
while (k)
{
if (k & 1) res = (ll)res * a % p;
a = (ll)a * a % p;
k >>= 1;
}
return res;
}
int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int a[N];
map<int, vector<int>> mp;
int dp[1 << 15], f[1 << 15];
int st[N];
void solve() {
cin >> n;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
int x = a[i];
for (int j = 0; j < 15; j ++ ) {
if (x % prime[j] == 0) {
st[i] |= (1 << j);
while (x % prime[j] == 0) {
x /= prime[j];
}
}
}
if (x == 53 * 53) x = 53;
mp[x].push_back(i);
}
dp[0] = 1;
for (auto &[x, vct] : mp) {
memset(f, 0, sizeof f);
for (auto i : vct) {
for (int s = (1 << 15) - 1; s >= 0; s -- ) {
f[s | st[i]] += dp[s] * (x == 1 ? a[i] : a[i] / x * (x - 1)) + f[s] * a[i];
f[s | st[i]] %= mod;
}
}
for (int s = 0; s < (1 << 15); s ++ ) dp[s] = (dp[s] + f[s]) % mod;
}
int ans = 0;
for (int s = 0; s < (1 << 15); s ++ ) {
int res = dp[s];
for (int i = 0; i < 15; i ++ ) {
if (s >> i & 1) {
res = res * (prime[i] - 1) % mod * qmi(prime[i], mod - 2, mod) % mod;
}
}
ans = (ans + res) % mod;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 4388kb
input:
5 1 6 8 6 2
output:
892
result:
ok single line: '892'
Test #2:
score: 0
Accepted
time: 28ms
memory: 4392kb
input:
5 3 8 3 7 8
output:
3157
result:
ok single line: '3157'
Test #3:
score: -100
Wrong Answer
time: 166ms
memory: 4184kb
input:
2000 79 1 1 1 1 1 1 2803 1 1 1 1 1 1 1609 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2137 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 613 1 499 1 211 1 2927 1 1 1327 1 1 1123 1 907 1 2543 1 1 1 311 2683 1 1 1 1 2963 1 1 1 641 761 1 1 1 1 1 1 1 1 1 1 1 1489 2857 1 1 1 1 1 1 1 1 1 1 1 1 1 967 1 821 1 1 1 1 2143 1861...
output:
828425969
result:
wrong answer 1st lines differ - expected: '50965652', found: '828425969'