problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
vector<int> r, g, b;
for (int i = 0; i < N; i++) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
long long ans = r.size() * g.size() * b.size();
int count = 0;
for (int i : r) {
for (int j : b) {
for (int k : g) {
vector<int> temp = {i, j, k};
sort(temp.begin(), temp.end());
if (temp[2] - temp[1] == temp[1] - temp[0]) {
count++;
}
}
}
}
cout << ans - count << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
vector<int> r, g, b;
for (int i = 0; i < N; i++) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
long long ans = r.size() * g.size() * b.size();
int count = 0;
for (int i : r) {
for (int j : b) {
int minn = min(i, j);
int maxx = max(i, j);
int d = maxx - minn;
if (minn - d >= 0 && s[minn - d] == 'G')
count++;
if (maxx + d < N && s[maxx + d] == 'G')
count++;
if ((i + j) % 2 == 0 && s[(i + j) / 2] == 'G')
count++;
}
}
cout << ans - count << endl;
return 0;
} | replace | 28 | 36 | 28 | 37 | TLE | |
p02714 | C++ | Time Limit Exceeded | // INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
// DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a) (a).begin(), (a).end()
#define ALL(a, n) (a), (a) + n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
// CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
// REPEAT
//------------------------------------------
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++)
#define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--)
#define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--)
#define WREP(i, in, j, jn) REP(i, in) REP(j, jn)
//-----------------------------------------
#define dcml(n) fixed << setprecision(n)
using namespace std;
int main(void) {
ll N;
string S;
cin >> N >> S;
ll cnt = 0;
REP(i, N - 2) {
FOR(j, i + 1, N - 1) {
if (S[i] == S[j])
continue;
FOR(k, j + 1, N) {
if (S[i] == S[k])
continue;
if (S[j] == S[k])
continue;
if (j - i == k - j)
continue;
cnt++;
}
}
}
cout << cnt << "\n";
} | // INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
// DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a) (a).begin(), (a).end()
#define ALL(a, n) (a), (a) + n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
// CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
// REPEAT
//------------------------------------------
#define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++)
#define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--)
#define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--)
#define WREP(i, in, j, jn) REP(i, in) REP(j, jn)
//-----------------------------------------
#define dcml(n) fixed << setprecision(n)
using namespace std;
int main(void) {
ll N;
string S;
cin >> N >> S;
ll cnt = 0;
ll n1 = 0, n2 = 0, n3 = 0;
REP(i, N) {
if (S[i] == 'R')
n1++;
else if (S[i] == 'G')
n2++;
else
n3++;
}
cnt = n1 * n2 * n3;
REP(i, N) {
for (ll k = 1; i + 2 * k < N; k++) {
if (S[i] != S[i + k] && S[i + k] != S[i + 2 * k] && S[i + 2 * k] != S[i])
cnt--;
}
}
cout << cnt << "\n";
} | replace | 34 | 47 | 34 | 48 | TLE | |
p02714 | C++ | Runtime Error | /*
ID: wangjun30
LANG: C++11
TASK:
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include<fstream>
#define int long long
using namespace std;
// ifstream cin(".in");
// ofstream cout(".out");
int Rf[4010];
int Gf[4010];
int Bf[4010];
int Rb[4010];
int Gb[4010];
int Bb[4010];
char ch[4010];
int ans = 0;
int Subans = 0;
int n;
int init() {
cin >> n;
int R = 0, G = 0, B = 0;
for (int i = 1; i <= n; i++) {
cin >> ch[i];
Rf[i] = R;
Gf[i] = G;
Bf[i] = B;
switch (ch[i]) {
case 'R': {
R++;
break;
}
case 'G': {
G++;
break;
}
case 'B': {
B++;
break;
}
}
}
R = 0;
G = 0;
B = 0;
for (int i = n; i >= 1; i--) {
Rb[i] = R;
Gb[i] = G;
Bb[i] = B;
switch (ch[i]) {
case 'R': {
R++;
break;
}
case 'G': {
G++;
break;
}
case 'B': {
B++;
break;
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
init();
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int Length = j - i;
int PlaceA = i - Length;
int PlaceB = i;
int PlaceC = i + Length;
if (PlaceC <= n && PlaceA >= 1 && ch[PlaceA] != ch[PlaceB] &&
ch[PlaceA] != ch[PlaceC] && ch[PlaceB] != ch[PlaceC])
Subans++;
}
}
for (int i = 1; i <= n; i++) {
switch (ch[i]) {
case 'R': {
ans += Gf[i] * Bb[i] + Gb[i] * Bf[i];
break;
}
case 'G': {
ans += Rf[i] * Bb[i] + Rb[i] * Bf[i];
break;
}
case 'B': {
ans += Rf[i] * Gb[i] + Rb[i] * Gf[i];
break;
}
}
}
cout << ans - Subans;
return 0;
} | /*
ID: wangjun30
LANG: C++11
TASK:
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include<fstream>
#define int long long
using namespace std;
// ifstream cin(".in");
// ofstream cout(".out");
int Rf[4010];
int Gf[4010];
int Bf[4010];
int Rb[4010];
int Gb[4010];
int Bb[4010];
char ch[4010];
int ans = 0;
int Subans = 0;
int n;
void init() {
cin >> n;
int R = 0, G = 0, B = 0;
for (int i = 1; i <= n; i++) {
cin >> ch[i];
Rf[i] = R;
Gf[i] = G;
Bf[i] = B;
switch (ch[i]) {
case 'R': {
R++;
break;
}
case 'G': {
G++;
break;
}
case 'B': {
B++;
break;
}
}
}
R = 0;
G = 0;
B = 0;
for (int i = n; i >= 1; i--) {
Rb[i] = R;
Gb[i] = G;
Bb[i] = B;
switch (ch[i]) {
case 'R': {
R++;
break;
}
case 'G': {
G++;
break;
}
case 'B': {
B++;
break;
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
init();
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int Length = j - i;
int PlaceA = i - Length;
int PlaceB = i;
int PlaceC = i + Length;
if (PlaceC <= n && PlaceA >= 1 && ch[PlaceA] != ch[PlaceB] &&
ch[PlaceA] != ch[PlaceC] && ch[PlaceB] != ch[PlaceC])
Subans++;
}
}
for (int i = 1; i <= n; i++) {
switch (ch[i]) {
case 'R': {
ans += Gf[i] * Bb[i] + Gb[i] * Bf[i];
break;
}
case 'G': {
ans += Rf[i] * Bb[i] + Rb[i] * Bf[i];
break;
}
case 'B': {
ans += Rf[i] * Gb[i] + Rb[i] * Gf[i];
break;
}
}
}
cout << ans - Subans;
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define inf 1e18 //(10^18
#define pqmax priority_queue<int>
#define mii map<int, int>
#define ps(x, y) fixed << setprecision(y) << x
// double ans = 1.012345668992
// cout<<ps(ans , 6)
// ans = 1.012345 // 6 decimal places
#define pqmin priority_queue<int, vi, greater<int>>
#define mk(arr, n, type) type *arr = new type[n];
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
// 48->11000(4) (returns no. of zeros after first one)
#define mod 1000000007 // 1e9 +7
#define w(t) \
int t; \
cin >> t; \
while (t--)
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// shuffle(arr , arr +n , rng)
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// pbds s;
// s.order_of_key(4);
//*s.find_by_order(4);
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int count = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
if ((s[i] != s[j]) && (s[i] != s[k]) && (s[j] != s[k]) &&
(j - i) != (k - j)) {
count++;
}
}
}
}
cout << count << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define inf 1e18 //(10^18
#define pqmax priority_queue<int>
#define mii map<int, int>
#define ps(x, y) fixed << setprecision(y) << x
// double ans = 1.012345668992
// cout<<ps(ans , 6)
// ans = 1.012345 // 6 decimal places
#define pqmin priority_queue<int, vi, greater<int>>
#define mk(arr, n, type) type *arr = new type[n];
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
// 48->11000(4) (returns no. of zeros after first one)
#define mod 1000000007 // 1e9 +7
#define w(t) \
int t; \
cin >> t; \
while (t--)
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// shuffle(arr , arr +n , rng)
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// pbds s;
// s.order_of_key(4);
//*s.find_by_order(4);
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int count = 0;
map<char, int> m;
for (int i = 0; i < n; i++) {
m[s[i]]++;
}
int r = m['R'];
int g = m['G'];
int b = m['B'];
count = r * g * b;
for (int i = 0; i <= (n - 3) / 2; i++) {
for (int j = 0; j + 2 * i + 2 < n; j++) {
if (s[j] != s[j + 1 + i] && s[j] != s[j + 2 * i + 2] &&
s[j + i + 1] != s[j + i * 2 + 2])
count--;
}
}
cout << count << "\n";
return 0;
}
| replace | 46 | 54 | 46 | 61 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
map<char, int> mp;
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
vector<vector<int>> colors(3, vector<int>());
for (int i = 0; i < n; i++) {
colors[mp[s[i]]].push_back(i);
}
long long sum = 0;
for (int i = 0; i < colors[0].size(); i++) {
for (int j = 0; j < colors[1].size(); j++) {
for (int k = 0; k < colors[2].size(); k++) {
int ri = colors[0][i];
int rj = colors[1][j];
int rk = colors[2][k];
if (ri > rj) {
swap(ri, rj);
}
if (rj > rk) {
swap(rj, rk);
}
if (ri > rj) {
swap(ri, rj);
}
if (rj - ri != rk - rj) {
sum++;
}
}
}
}
printf("%lld\n", sum);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
map<char, int> mp;
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
vector<vector<int>> colors(3, vector<int>());
for (int i = 0; i < n; i++) {
colors[mp[s[i]]].push_back(i);
}
long long sum = colors[0].size() * colors[1].size() * colors[2].size();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n && (j - i) + j < n; j++) {
int k = (j - i) + j;
if (k < j) {
continue;
}
if (s[i] != s[j] && s[i] != s[k] && s[k] != s[j]) {
sum--;
}
}
}
printf("%lld\n", sum);
return 0;
} | replace | 25 | 44 | 25 | 35 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
vll r, g, b;
rep(i, s.size()) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
// for (auto elem : r) cout << elem << " "; cout << endl;
// for (auto elem : g) cout << elem << " "; cout << endl;
// for (auto elem : b) cout << elem << " "; cout << endl;
ll sum = 0;
rep(i, r.size()) {
rep(j, g.size()) {
rep(k, b.size()) {
vll _l;
_l.push_back(r[i]);
_l.push_back(g[j]);
_l.push_back(b[k]);
sort(all(_l));
if (_l[2] - _l[1] != _l[1] - _l[0])
sum++;
}
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
vll r, g, b;
rep(i, s.size()) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
// for (auto elem : r) cout << elem << " "; cout << endl;
// for (auto elem : g) cout << elem << " "; cout << endl;
// for (auto elem : b) cout << elem << " "; cout << endl;
ll sum = 0;
rep(i, r.size()) {
rep(j, g.size()) {
sum += b.size();
if (r[i] < g[j]) {
ll diff = g[j] - r[i];
ll low = r[i] - (diff);
if (0 <= low && s[low] == 'B')
sum--;
ll high = g[j] + diff;
if (high < n && s[high] == 'B')
sum--;
ll middle = (r[i] + diff / 2);
if (diff % 2 == 0 && s[middle] == 'B')
sum--;
} else {
ll diff = r[i] - g[j];
ll low = g[j] - diff;
if (0 <= low && s[low] == 'B')
sum--;
ll high = r[i] + diff;
if (high < n && s[high] == 'B')
sum--;
ll middle = (g[j] + diff / 2);
if (diff % 2 == 0 && s[middle] == 'B')
sum--;
}
}
}
cout << sum << endl;
return 0;
} | replace | 31 | 39 | 31 | 58 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
int ans = 0;
for (int i = 0; i < r.size(); ++i) {
for (int j = 0; j < g.size(); ++j) {
for (int k = 0; k < b.size(); k++) {
vector<int> l;
l.push_back(r[i]);
l.push_back(g[j]);
l.push_back(b[k]);
sort(l.begin(), l.end());
if (l[2] - l[1] != l[1] - l[0])
++ans;
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
long long ans = r.size() * b.size() * g.size();
for (int i = 0; i < n - 1; ++i) {
for (int j = i; j < n; ++j) {
int k = j + j - i;
if (k >= n)
continue;
if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
--ans;
}
}
cout << ans << endl;
return 0;
} | replace | 28 | 41 | 28 | 36 | TLE | |
p02714 | C++ | Runtime Error | // garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a, ll b, ll p) {
ll res = 1;
a %= p;
while (b > 0) {
if (b & 1)
res = (res * a) % p;
a = (a * a) % p;
b >>= 1;
}
return res;
}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int r[4004], g[4004], b[4004];
int rs[4004], gs[4004], bs[4004];
ll count(int a[], int b[], int c[], int d[]) {
ll ans = 0;
for (int i = 0; i < 4001; i++) {
for (int j = i + 1; j < 4001; j++) {
if (a[i] && b[j]) {
int nk = 2 * j - i;
// cout<<i.F<<" "<<j.F<<" "<<nk<<"\n";
ans += (d[j + 1] - c[nk]);
}
}
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r[i] = 1;
else if (s[i] == 'G')
g[i] = 1;
else
b[i] = 1;
}
for (int i = n - 1; i >= 0; i--) {
rs[i] = r[i] + rs[i + 1];
gs[i] = g[i] + gs[i + 1];
bs[i] = b[i] + bs[i + 1];
}
ll ans = 0;
// RGB
ans += count(r, g, b, bs);
// RBG
ans += count(r, b, g, gs);
// GBR
ans += count(g, b, r, rs);
// GRB
ans += count(g, r, b, bs);
// BRG
ans += count(b, r, g, gs);
// BGR
ans += count(b, g, r, rs);
cout << ans;
return 0;
} | // garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a, ll b, ll p) {
ll res = 1;
a %= p;
while (b > 0) {
if (b & 1)
res = (res * a) % p;
a = (a * a) % p;
b >>= 1;
}
return res;
}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int r[4004], g[4004], b[4004];
int rs[4004], gs[4004], bs[4004];
ll count(int a[], int b[], int c[], int d[]) {
ll ans = 0;
for (int i = 0; i < 4001; i++) {
for (int j = i + 1; j < 4001; j++) {
if (a[i] && b[j]) {
int nk = 2 * j - i;
// cout<<i.F<<" "<<j.F<<" "<<nk<<"\n";
ans += d[j + 1];
if (nk < 4001)
ans -= c[nk];
}
}
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r[i] = 1;
else if (s[i] == 'G')
g[i] = 1;
else
b[i] = 1;
}
for (int i = n - 1; i >= 0; i--) {
rs[i] = r[i] + rs[i + 1];
gs[i] = g[i] + gs[i + 1];
bs[i] = b[i] + bs[i + 1];
}
ll ans = 0;
// RGB
ans += count(r, g, b, bs);
// RBG
ans += count(r, b, g, gs);
// GBR
ans += count(g, b, r, rs);
// GRB
ans += count(g, r, b, bs);
// BRG
ans += count(b, r, g, gs);
// BGR
ans += count(b, g, r, rs);
cout << ans;
return 0;
} | replace | 35 | 36 | 35 | 38 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
r.push_back(i);
else if (S[i] == 'G')
g.push_back(i);
else if (S[i] == 'B')
b.push_back(i);
}
long long ans1 = 0;
auto f = [&ans1](vector<int> &r, vector<int> &g, vector<int> &b) {
for (int i = 0; i < r.size(); i++) {
int j = upper_bound(g.begin(), g.end(), r[i]) - g.begin();
for (; j < g.size(); j++) {
auto it = lower_bound(b.begin(), b.end(), g[j] * 2 - r[i]);
if (g[j] - r[i] == *it - g[j])
ans1++;
}
}
};
f(r, g, b);
f(r, b, g);
f(g, b, r);
f(g, r, b);
f(b, r, g);
f(b, g, r);
long long ans = r.size() * g.size() * b.size() - ans1;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < N; i++) {
if (S[i] == 'R')
r.push_back(i);
else if (S[i] == 'G')
g.push_back(i);
else if (S[i] == 'B')
b.push_back(i);
}
long long ans1 = 0;
auto f = [&ans1](vector<int> &r, vector<int> &g, vector<int> &b) {
for (int i = 0; i < r.size(); i++) {
int j = upper_bound(g.begin(), g.end(), r[i]) - g.begin();
for (; j < g.size(); j++) {
auto it = lower_bound(b.begin(), b.end(), g[j] * 2 - r[i]);
if (it != b.end() && g[j] - r[i] == *it - g[j])
ans1++;
}
}
};
f(r, g, b);
f(r, b, g);
f(g, b, r);
f(g, r, b);
f(b, r, g);
f(b, g, r);
long long ans = r.size() * g.size() * b.size() - ans1;
cout << ans << endl;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
long long r = 0, g = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R')
r++;
if (s.at(i) == 'G')
g++;
if (s.at(i) == 'B')
b++;
}
int exc = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
for (int k = j + 1; k <= n; k++) {
if (j - i == k - j && s.at(i - 1) != s.at(j - 1) &&
s.at(j - 1) != s.at(k - 1) && s.at(k - 1) != s.at(i - 1))
exc++;
}
}
}
cout << r * g * b - exc << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
long long r = 0, g = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R')
r++;
if (s.at(i) == 'G')
g++;
if (s.at(i) == 'B')
b++;
}
int exc = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if ((2 * j - i) < n) {
if (s.at(i) != s.at(j) && s.at(j) != s.at(2 * j - i) &&
s.at(2 * j - i) != s.at(i))
exc++;
}
}
}
cout << r * g * b - exc << endl;
return 0;
} | replace | 20 | 25 | 20 | 25 | TLE | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int biggerI(vector<int> &v, int val, int offset = 0) {
int left = offset;
if (v[left] >= val)
return left;
int right = v.size();
if (v[right - 1] < val)
return right;
while (left + 1 < right) {
int mid = (left + right) / 2;
if (v[mid] < val)
left = mid;
else
right = mid;
}
if (v[left] >= val)
return left;
else
return right;
}
int main() {
int n;
cin >> n;
vector<int> r, g, b;
string s;
cin >> s;
for (int i = 1; i <= n; i++) {
char c = s[i - 1];
if (c == 'R')
r.push_back(i);
else if (c == 'G')
g.push_back(i);
else
b.push_back(i);
}
sort(r.begin(), r.end());
sort(g.begin(), g.end());
sort(b.begin(), b.end());
ll sum = 0;
int sec_lst = 0;
for (int i = 0; i < r.size(); i++) {
int j = biggerI(g, r[i], sec_lst);
if (j == g.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < g.size(); j++) {
int k = biggerI(b, g[j], trd_lst);
if (k == b.size())
break;
sum += b.size() - k;
if (2 * g[j] - r[i] - 1 < n && s[2 * g[j] - r[i] - 1] == 'B')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < r.size(); i++) {
int j = biggerI(b, r[i], sec_lst);
if (j == b.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < b.size(); j++) {
int k = biggerI(g, b[j], trd_lst);
if (k == g.size())
break;
sum += g.size() - k;
if (2 * b[j] - r[i] - 1 < n && s[2 * b[j] - r[i] - 1] == 'G')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < g.size(); i++) {
int j = biggerI(b, g[i], sec_lst);
if (j == b.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < b.size(); j++) {
int k = biggerI(r, b[j], trd_lst);
if (k == r.size())
break;
sum += r.size() - k;
if (2 * b[j] - g[i] - 1 < n && s[2 * b[j] - g[i] - 1] == 'R')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < g.size(); i++) {
int j = biggerI(r, g[i], sec_lst);
if (j == r.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < r.size(); j++) {
int k = biggerI(b, r[j], trd_lst);
if (k == b.size())
break;
sum += b.size() - k;
if (2 * r[j] - g[i] - 1 < n && s[2 * r[j] - g[i] - 1] == 'B')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < b.size(); i++) {
int j = biggerI(r, b[i], sec_lst);
if (j == r.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < r.size(); j++) {
int k = biggerI(g, r[j], trd_lst);
if (k == g.size())
break;
sum += g.size() - k;
if (2 * r[j] - b[i] - 1 < n && s[2 * r[j] - b[i] - 1] == 'G')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < b.size(); i++) {
int j = biggerI(g, b[i], sec_lst);
if (j == g.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < g.size(); j++) {
int k = biggerI(r, g[j], trd_lst);
if (k == r.size())
break;
sum += r.size() - k;
if (2 * g[j] - b[i] - 1 < n && s[2 * g[j] - b[i] - 1] == 'R')
sum--;
trd_lst = k;
}
}
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int biggerI(vector<int> &v, int val, int offset = 0) {
int left = offset;
if (offset >= v.size())
return v.size();
if (v[left] >= val)
return left;
int right = v.size();
if (v[right - 1] < val)
return right;
while (left + 1 < right) {
int mid = (left + right) / 2;
if (v[mid] < val)
left = mid;
else
right = mid;
}
if (v[left] >= val)
return left;
else
return right;
}
int main() {
int n;
cin >> n;
vector<int> r, g, b;
string s;
cin >> s;
for (int i = 1; i <= n; i++) {
char c = s[i - 1];
if (c == 'R')
r.push_back(i);
else if (c == 'G')
g.push_back(i);
else
b.push_back(i);
}
sort(r.begin(), r.end());
sort(g.begin(), g.end());
sort(b.begin(), b.end());
ll sum = 0;
int sec_lst = 0;
for (int i = 0; i < r.size(); i++) {
int j = biggerI(g, r[i], sec_lst);
if (j == g.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < g.size(); j++) {
int k = biggerI(b, g[j], trd_lst);
if (k == b.size())
break;
sum += b.size() - k;
if (2 * g[j] - r[i] - 1 < n && s[2 * g[j] - r[i] - 1] == 'B')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < r.size(); i++) {
int j = biggerI(b, r[i], sec_lst);
if (j == b.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < b.size(); j++) {
int k = biggerI(g, b[j], trd_lst);
if (k == g.size())
break;
sum += g.size() - k;
if (2 * b[j] - r[i] - 1 < n && s[2 * b[j] - r[i] - 1] == 'G')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < g.size(); i++) {
int j = biggerI(b, g[i], sec_lst);
if (j == b.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < b.size(); j++) {
int k = biggerI(r, b[j], trd_lst);
if (k == r.size())
break;
sum += r.size() - k;
if (2 * b[j] - g[i] - 1 < n && s[2 * b[j] - g[i] - 1] == 'R')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < g.size(); i++) {
int j = biggerI(r, g[i], sec_lst);
if (j == r.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < r.size(); j++) {
int k = biggerI(b, r[j], trd_lst);
if (k == b.size())
break;
sum += b.size() - k;
if (2 * r[j] - g[i] - 1 < n && s[2 * r[j] - g[i] - 1] == 'B')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < b.size(); i++) {
int j = biggerI(r, b[i], sec_lst);
if (j == r.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < r.size(); j++) {
int k = biggerI(g, r[j], trd_lst);
if (k == g.size())
break;
sum += g.size() - k;
if (2 * r[j] - b[i] - 1 < n && s[2 * r[j] - b[i] - 1] == 'G')
sum--;
trd_lst = k;
}
}
sec_lst = 0;
for (int i = 0; i < b.size(); i++) {
int j = biggerI(g, b[i], sec_lst);
if (j == g.size())
break;
sec_lst = j;
int trd_lst = 0;
for (; j < g.size(); j++) {
int k = biggerI(r, g[j], trd_lst);
if (k == r.size())
break;
sum += r.size() - k;
if (2 * g[j] - b[i] - 1 < n && s[2 * g[j] - b[i] - 1] == 'R')
sum--;
trd_lst = k;
}
}
cout << sum << endl;
return 0;
}
| insert | 11 | 11 | 11 | 13 | 0 | |
p02714 | C++ | Time Limit Exceeded | #define _DEBUG 1
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif
void solve(ll N, std::string S) {
ll result = 0;
ll cntR = 0;
ll cntG = 0;
ll cntB = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == 'R')
cntR++;
if (S.at(i) == 'G')
cntG++;
if (S.at(i) == 'B')
cntB++;
}
ll e = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
if (S.at(i) == S.at(j))
continue;
for (int k = j + 1; k < N; k++) {
if (S.at(k) == S.at(i) || S.at(k) == S.at(j))
continue;
if (j - i == k - j)
e++;
}
}
}
result = cntR * cntG * cntB - e;
cout << result << endl;
}
int main() {
ll N;
scanf("%lld", &N);
std::string S;
std::cin >> S;
solve(N, S);
return 0;
}
| #define _DEBUG 1
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif
void solve(ll N, std::string S) {
ll result = 0;
ll cntR = 0;
ll cntG = 0;
ll cntB = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == 'R')
cntR++;
if (S.at(i) == 'G')
cntG++;
if (S.at(i) == 'B')
cntB++;
}
ll e = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
if (S.at(i) == S.at(j))
continue;
int k = 2 * j - i;
if (k < N && S.at(i) != S.at(j) && S.at(j) != S.at(k) &&
S.at(k) != S.at(i)) {
e++;
}
}
}
result = cntR * cntG * cntB - e;
cout << result << endl;
}
int main() {
ll N;
scanf("%lld", &N);
std::string S;
std::cin >> S;
solve(N, S);
return 0;
}
| replace | 43 | 48 | 43 | 47 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int N;
string S;
int sum[3][4000];
int main() {
cin >> N >> S;
map<char, int> mm;
char tmpc[3] = {'R', 'G', 'B'};
REP(i, 3) mm[tmpc[i]] = i;
REP(i, N) {
++sum[mm[S[i]]][i + 1];
REP(j, 3) sum[j][i + 1] += sum[j][i];
}
ll ans = 0;
for (int i = N - 1; i >= 0; --i) {
for (int j = i - 1; j >= 0; --j) {
if (S[i] == S[j])
continue;
bool f[3]{};
f[mm[S[i]]] = true;
f[mm[S[j]]] = true;
int cc;
REP(k, 3) if (!f[k]) cc = k;
ans += sum[cc][j];
int k = j - (i - j);
if (k >= 0 && S[k] != S[i] && S[k] != S[j])
--ans;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int N;
string S;
int sum[3][4001];
int main() {
cin >> N >> S;
map<char, int> mm;
char tmpc[3] = {'R', 'G', 'B'};
REP(i, 3) mm[tmpc[i]] = i;
REP(i, N) {
++sum[mm[S[i]]][i + 1];
REP(j, 3) sum[j][i + 1] += sum[j][i];
}
ll ans = 0;
for (int i = N - 1; i >= 0; --i) {
for (int j = i - 1; j >= 0; --j) {
if (S[i] == S[j])
continue;
bool f[3]{};
f[mm[S[i]]] = true;
f[mm[S[j]]] = true;
int cc;
REP(k, 3) if (!f[k]) cc = k;
ans += sum[cc][j];
int k = j - (i - j);
if (k >= 0 && S[k] != S[i] && S[k] != S[j])
--ans;
}
}
cout << ans << endl;
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02714 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <tuple>
#define INF INT_MAX >> 1
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, from, to) for (int i = (from); i < (int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) \
for (int i = 0; i < (int)(name.size()); i++) \
cin >> name[i];
#define voutput(name) \
for (int i = 0; i < (int)(name.size()); i++) \
cout << name[i] << endl;
typedef long long ll;
using namespace std;
ll ans = 0;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vint R, G, B;
rep(i, n) {
if (s[i] == 'R')
R.push_back(i + 1);
if (s[i] == 'G')
G.push_back(i + 1);
if (s[i] == 'B')
B.push_back(i + 1);
}
rep(r, R.size()) {
rep(g, G.size()) {
rep(b, B.size()) {
vint v;
v.push_back(R[r]);
v.push_back(G[g]);
v.push_back(B[b]);
sort(all(v));
if (v[1] - v[0] != v[2] - v[1])
ans++;
}
}
}
cout << ans << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <tuple>
#define INF INT_MAX >> 1
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, from, to) for (int i = (from); i < (int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) \
for (int i = 0; i < (int)(name.size()); i++) \
cin >> name[i];
#define voutput(name) \
for (int i = 0; i < (int)(name.size()); i++) \
cout << name[i] << endl;
typedef long long ll;
using namespace std;
ll ans = 0;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vint R, G, B;
rep(i, n) {
if (s[i] == 'R')
R.push_back(i + 1);
if (s[i] == 'G')
G.push_back(i + 1);
if (s[i] == 'B')
B.push_back(i + 1);
}
ll ans = R.size() * G.size() * B.size();
rep(i, n) {
for (int j = 1; i - j >= 0 && i + j < n; j++) {
if (s[i - j] != s[i] && s[i + j] != s[i] && s[i - j] != s[i + j]) {
ans--;
}
}
}
cout << ans << endl;
return 0;
} | replace | 52 | 62 | 52 | 57 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll count(vector<int> &R, vector<int> &G, vector<int> &B) {
ll sum = 0;
for (int i = 0; i < R.size(); i++) {
for (int j = 0; j < G.size(); j++) {
if (R[i] > G[j]) {
continue;
}
int a = G[j] - R[i];
for (int k = 0; k < B.size(); k++) {
if (G[j] > B[k]) {
continue;
}
if (a == B[k] - G[j]) {
continue;
}
sum++;
}
}
}
return sum;
}
int main() {
int N;
char S;
vector<int> R, G, B;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
if (S == 'R') {
R.push_back(i);
} else if (S == 'G') {
G.push_back(i);
} else if (S == 'B') {
B.push_back(i);
}
}
ll sum = 0;
sum += count(R, B, G);
sum += count(R, G, B);
sum += count(B, R, G);
sum += count(B, G, R);
sum += count(G, R, B);
sum += count(G, B, R);
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
ll count(vector<int> &R, vector<int> &G, vector<int> &B) {
ll sum = 0;
for (int i = 0; i < R.size(); i++) {
for (auto j = std::lower_bound(G.begin(), G.end(), R[i]); j < G.end();
j++) {
int a = *j - R[i];
for (auto k = std::lower_bound(B.begin(), B.end(), *j); k < B.end();
k++) {
if (a == *k - *j) {
continue;
}
sum++;
}
}
}
return sum;
}
int main() {
int N;
char S;
vector<int> R, G, B;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
if (S == 'R') {
R.push_back(i);
} else if (S == 'G') {
G.push_back(i);
} else if (S == 'B') {
B.push_back(i);
}
}
ll sum = 0;
sum += count(R, B, G);
sum += count(R, G, B);
sum += count(B, R, G);
sum += count(B, G, R);
sum += count(G, R, B);
sum += count(G, B, R);
cout << sum << endl;
return 0;
} | replace | 13 | 23 | 13 | 19 | TLE | |
p02714 | C++ | Runtime Error | #include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
bool red[4005];
bool green[4005];
bool blue[4005];
int rr[10005];
int gg[10005];
int bb[10005];
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
red[i] = true;
else if (s[i] == 'G')
green[i] = true;
else
blue[i] = true;
}
for (int j = n - 1; j >= 0; j--) {
if (s[j] == 'R')
rr[j]++;
if (s[j] == 'G')
gg[j]++;
if (s[j] == 'B')
bb[j]++;
rr[j] += rr[j + 1];
gg[j] += gg[j + 1];
bb[j] += bb[j + 1];
}
ll ans = 0;
// cout << rr[0] <<" "<<gg[0]<<" "<<bb[0] << endl;
for (int i = 0; i < n - 2; i++) {
if (s[i] == 'R') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'R')
continue;
if (s[j] == 'G') {
ans += bb[j + 1];
if (blue[2 * j - i])
ans--;
}
if (s[j] == 'B') {
ans += gg[j + 1];
if (green[2 * j - i])
ans--;
}
}
}
if (s[i] == 'G') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'G')
continue;
if (s[j] == 'R') {
ans += bb[j + 1];
if (blue[2 * j - i])
ans--;
}
if (s[j] == 'B') {
ans += rr[j + 1];
if (red[2 * j - i])
ans--;
}
}
}
if (s[i] == 'B') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'B')
continue;
if (s[j] == 'G') {
ans += rr[j + 1];
if (red[2 * j - i])
ans--;
}
if (s[j] == 'R') {
ans += gg[j + 1];
if (green[2 * j - i])
ans--;
}
}
}
// cout << ans << endl;
}
cout << ans << endl;
}
| #include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
bool red[10005];
bool green[10005];
bool blue[10005];
int rr[10005];
int gg[10005];
int bb[10005];
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
red[i] = true;
else if (s[i] == 'G')
green[i] = true;
else
blue[i] = true;
}
for (int j = n - 1; j >= 0; j--) {
if (s[j] == 'R')
rr[j]++;
if (s[j] == 'G')
gg[j]++;
if (s[j] == 'B')
bb[j]++;
rr[j] += rr[j + 1];
gg[j] += gg[j + 1];
bb[j] += bb[j + 1];
}
ll ans = 0;
// cout << rr[0] <<" "<<gg[0]<<" "<<bb[0] << endl;
for (int i = 0; i < n - 2; i++) {
if (s[i] == 'R') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'R')
continue;
if (s[j] == 'G') {
ans += bb[j + 1];
if (blue[2 * j - i])
ans--;
}
if (s[j] == 'B') {
ans += gg[j + 1];
if (green[2 * j - i])
ans--;
}
}
}
if (s[i] == 'G') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'G')
continue;
if (s[j] == 'R') {
ans += bb[j + 1];
if (blue[2 * j - i])
ans--;
}
if (s[j] == 'B') {
ans += rr[j + 1];
if (red[2 * j - i])
ans--;
}
}
}
if (s[i] == 'B') {
for (int j = i + 1; j < n - 1; j++) {
if (s[j] == 'B')
continue;
if (s[j] == 'G') {
ans += rr[j + 1];
if (red[2 * j - i])
ans--;
}
if (s[j] == 'R') {
ans += gg[j + 1];
if (green[2 * j - i])
ans--;
}
}
}
// cout << ans << endl;
}
cout << ans << endl;
}
| replace | 6 | 9 | 6 | 9 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
vvl cs(3);
rep(i, n) {
if (s[i] == 'R')
cs[0].push_back(i);
else if (s[i] == 'G')
cs[1].push_back(i);
else if (s[i] == 'B')
cs[2].push_back(i);
}
ll ans = 0;
rep(i, 3) {
rep(j, 2) {
int c1 = i, c2 = (c1 + j + 1) % 3, c3 = 3 - c1 - c2;
for (auto r : cs[c1]) {
auto it = lower_bound(rng(cs[c2]), r);
for (; it != cs[c2].end(); ++it) {
auto it2 = lower_bound(rng(cs[c3]), *it);
ans += cs[c3].end() - it2;
if (*lower_bound(rng(cs[c3]), 2 * (*it) - r) == 2 * (*it) - r)
ans--;
}
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
vvl cs(3);
rep(i, n) {
if (s[i] == 'R')
cs[0].push_back(i);
else if (s[i] == 'G')
cs[1].push_back(i);
else if (s[i] == 'B')
cs[2].push_back(i);
}
ll ans = 0;
rep(i, 3) {
rep(j, 2) {
int c1 = i, c2 = (c1 + j + 1) % 3, c3 = 3 - c1 - c2;
for (auto r : cs[c1]) {
auto it = lower_bound(rng(cs[c2]), r);
for (; it != cs[c2].end(); ++it) {
auto it2 = lower_bound(rng(cs[c3]), *it);
ans += cs[c3].end() - it2;
auto it3 = lower_bound(rng(cs[c3]), 2 * (*it) - r);
if (it3 != cs[c3].end() && *it3 == 2 * (*it) - r)
ans--;
}
}
}
}
cout << ans << endl;
} | replace | 73 | 74 | 73 | 75 | 0 | |
p02714 | C++ | Runtime Error | // God put a smile upon your face <3
#include <bits/stdc++.h>
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair<long long, long long>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
using namespace std;
bool check(ll n, ll pos) { return n & (1LL << pos); }
ll Set(ll n, ll pos) { return n = n | (1LL << pos); }
vector<ll> g[3];
string str;
map<char, ll> mp;
ll solve(ll id, ll id1, ll id2) {
ll cnt = upper_bound(g[id1].begin(), g[id1].end(), id) - g[id1].begin();
ll ret = 0;
for (auto it : g[id2]) {
if (it < id)
continue;
ret += cnt;
ll minuss = 2 * id - it;
auto jt = lower_bound(g[id1].begin(), g[id1].end(), minuss);
// cout << *jt << " " << minuss << endl;
if (*jt < id && *jt == minuss)
ret--;
}
// cout << id1 << " " << id2 << " " << cnt << " " << ret << endl;
return ret;
}
int main() {
ll i, j, k, l, m, n, o, r, q;
ll testcase;
ll input, flag, tag, ans;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while (cin >> n >> str) {
ans = 0;
for (ll i = 0; i < 3; i++)
g[i].clear();
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
for (ll i = 0; i < str.size(); i++) {
g[mp[str[i]]].pb(i);
}
for (ll i = 1; i + 1 < str.size(); i++) {
ll idx = mp[str[i]];
ll idx1 = (idx + 1) % 3;
ll idx2 = (idx + 2) % 3;
ans += solve(i, idx1, idx2);
ans += solve(i, idx2, idx1);
}
cout << ans << "\n";
}
}
| // God put a smile upon your face <3
#include <bits/stdc++.h>
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair<long long, long long>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
using namespace std;
bool check(ll n, ll pos) { return n & (1LL << pos); }
ll Set(ll n, ll pos) { return n = n | (1LL << pos); }
vector<ll> g[3];
string str;
map<char, ll> mp;
ll solve(ll id, ll id1, ll id2) {
ll cnt = upper_bound(g[id1].begin(), g[id1].end(), id) - g[id1].begin();
ll ret = 0;
for (auto it : g[id2]) {
if (it < id)
continue;
ret += cnt;
ll minuss = 2 * id - it;
auto jt = lower_bound(g[id1].begin(), g[id1].end(), minuss);
if (jt == g[id1].end())
continue;
// cout << *jt << " " << minuss << endl;
if (*jt < id && *jt == minuss)
ret--;
}
// cout << id1 << " " << id2 << " " << cnt << " " << ret << endl;
return ret;
}
int main() {
ll i, j, k, l, m, n, o, r, q;
ll testcase;
ll input, flag, tag, ans;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while (cin >> n >> str) {
ans = 0;
for (ll i = 0; i < 3; i++)
g[i].clear();
mp['R'] = 0;
mp['G'] = 1;
mp['B'] = 2;
for (ll i = 0; i < str.size(); i++) {
g[mp[str[i]]].pb(i);
}
for (ll i = 1; i + 1 < str.size(); i++) {
ll idx = mp[str[i]];
ll idx1 = (idx + 1) % 3;
ll idx2 = (idx + 2) % 3;
ans += solve(i, idx1, idx2);
ans += solve(i, idx2, idx1);
}
cout << ans << "\n";
}
}
| insert | 52 | 52 | 52 | 55 | 0 | |
p02714 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N;
char S[4000];
long long int count = 0;
long long int r, g, b;
r = 0;
g = 0;
b = 0;
long long int set, ans;
cin >> N;
cin >> S;
for (int i = 0; i < N; i++) {
if (S[i] == 'R') {
r++;
}
}
for (int i = 0; i < N; i++) {
if (S[i] == 'G') {
g++;
}
}
for (int i = 0; i < N; i++) {
if (S[i] == 'B') {
b++;
}
}
set = r * g * b;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
long long int k = j * 2 - i;
if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k]) && k < N) {
count++;
}
}
}
ans = set - count;
cout << ans << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int N;
char S[4000];
long long int count = 0;
long long int r, g, b;
r = 0;
g = 0;
b = 0;
long long int set, ans;
cin >> N;
cin >> S;
for (int i = 0; i < N; i++) {
if (S[i] == 'R') {
r++;
}
}
for (int i = 0; i < N; i++) {
if (S[i] == 'G') {
g++;
}
}
for (int i = 0; i < N; i++) {
if (S[i] == 'B') {
b++;
}
}
set = r * g * b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
long long int k = j * 2 - i;
if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k]) && k < N) {
count++;
}
}
}
ans = set - count;
cout << ans << endl;
return 0;
}
| replace | 36 | 38 | 36 | 38 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N;
cin >> S;
int sum = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
for (int k = j + 1; k < N; k++) {
if (S.at(j) != S.at(k) && S.at(i) != S.at(k) && S.at(j) != S.at(i)) {
if ((j - i) != (k - j)) {
sum++;
}
}
}
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string s;
cin >> N >> s;
long long int r, g, b;
r = 0, g = 0, b = 0;
for (char ch : s) {
if (ch == 'R')
r++;
else if (ch == 'G')
g++;
else if (ch == 'B')
b++;
}
long long int sum = r * g * b;
for (int i = 0; i < N; i++) {
for (int k = i + 2; k < N; k += 2) {
int j = (i + k) / 2;
if (s.at(i) + s.at(j) + s.at(k) == 'R' + 'G' + 'B') {
sum--;
}
}
}
cout << sum << endl;
} | replace | 4 | 16 | 4 | 22 | TLE | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll N, i, j, k, ans;
string S;
cin >> N >> S;
ans = 0;
for (i = 0; i < N - 2; i++) {
for (j = i + 1; j < N - 1; j++) {
for (k = j + 1; k < N; k++) {
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && j - i != k - j)
ans++;
}
}
}
cout << ans << endl;
} | #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll N, i, j, k, ans;
string S;
cin >> N >> S;
ans = 0;
for (i = 0; i < N - 2; i++) {
for (j = i + 1; j < N - 1; j++) {
for (k = j + 1; k < N; k++) {
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && j - i != k - j)
ans++;
}
}
}
cout << ans << endl;
} | replace | 0 | 3 | 0 | 3 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
unordered_map<char, int> mp;
const int N = 40010;
int a[4][N];
int main() {
int n;
string s;
cin >> n >> s;
mp['R'] = 1, mp['G'] = 2, mp['B'] = 3;
s = " " + s;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3; j++)
a[j][i] = a[j][i - 1];
a[mp[s[i]]][i]++;
}
long long cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (s[i] == s[j])
continue;
int x = 6 - mp[s[i]] - mp[s[j]];
cnt += a[x][n] - a[x][j] - (mp[s[2 * j - i]] == x);
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
unordered_map<char, int> mp;
const int N = 40010;
int a[4][N];
int main() {
int n;
string s;
cin >> n >> s;
mp['R'] = 1, mp['G'] = 2, mp['B'] = 3;
s = " " + s;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 3; j++)
a[j][i] = a[j][i - 1];
a[mp[s[i]]][i]++;
}
long long cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (s[i] == s[j])
continue;
int x = 6 - mp[s[i]] - mp[s[j]];
cnt += a[x][n] - a[x][j];
if (2 * j - i <= n)
cnt -= (mp[s[2 * j - i]] == x);
}
}
cout << cnt << endl;
return 0;
}
| replace | 22 | 23 | 22 | 26 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
cin >> s;
int t = 0;
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
if (s[i] == s[j]) {
continue;
}
for (int k = j; k < n; ++k) {
if (s[i] == s[k]) {
continue;
}
if (s[j] == s[k]) {
continue;
}
// if(s[i] != s[j]) {
// if(s[i] != s[k]) {
// if(s[j] != s[k]) {
if ((j - i) != (k - j)) {
t += 1;
// cout << i << j << k;
}
//}
//}
//}
}
}
}
cout << t << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
cin >> s;
long long rt = 0;
long long gt = 0;
long long bt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
rt += 1;
}
if (s[i] == 'G') {
gt += 1;
}
if (s[i] == 'B') {
bt += 1;
}
}
long long t = rt * gt * bt;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
int k = 2 * j - i;
if (k < n && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
t--;
}
}
}
cout << t << endl;
return 0;
}
| replace | 10 | 33 | 10 | 32 | TLE | |
p02714 | C++ | Runtime Error | // agrawal117
// chahatagrawal117
#include <bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
vector<ll> v[4];
int idx(char a, char b) {
if (b == 'R')
swap(a, b);
if (a == 'R' && b == 'G')
return 3;
if (a == 'R' && b == 'B')
return 2;
else
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R')
v[1].push_back(i);
else if (s[i] == 'G')
v[2].push_back(i);
else
v[3].push_back(i);
}
ll ans = 0;
for (int j = 1; j < s.size() - 1; j++) {
for (int i = 0; i < j; i++) {
if (s[j] != s[i]) {
int kk = idx(s[i], s[j]);
int k = lower_bound(v[kk].begin(), v[kk].end(), j) - v[kk].begin();
ans += (v[kk].size() - k);
k = lower_bound(v[kk].begin(), v[kk].end(), 2 * j - i) - v[kk].begin();
if (v[kk][k] == (2 * j) - i)
ans--;
}
}
}
cout << ans << endl;
} | // agrawal117
// chahatagrawal117
#include <bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
vector<ll> v[4];
int idx(char a, char b) {
if (b == 'R')
swap(a, b);
if (a == 'R' && b == 'G')
return 3;
if (a == 'R' && b == 'B')
return 2;
else
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R')
v[1].push_back(i);
else if (s[i] == 'G')
v[2].push_back(i);
else
v[3].push_back(i);
}
ll ans = 0;
for (int j = 1; j < s.size() - 1; j++) {
for (int i = 0; i < j; i++) {
if (s[j] != s[i]) {
int kk = idx(s[i], s[j]);
int k = lower_bound(v[kk].begin(), v[kk].end(), j) - v[kk].begin();
ans += (v[kk].size() - k);
k = lower_bound(v[kk].begin(), v[kk].end(), 2 * j - i) - v[kk].begin();
if (k != v[kk].size() && v[kk][k] == (2 * j) - i)
ans--;
}
}
}
cout << ans << endl;
} | replace | 44 | 45 | 44 | 45 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^・ω・^=)"
#define read_input freopen("in.txt", "r", stdin)
#define print_output freopen("out.txt", "w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
const ll maxn = 4e3 + 10;
ll pre[4][maxn], a[maxn];
ll other(ll a, ll b) {
if (a > b)
swap(a, b);
if (a == 1 && b == 2)
return 3;
if (a == 1 && b == 3)
return 2;
if (a == 2 && b == 3)
return 1;
}
int main() {
ll n;
string s;
cin >> n >> s;
for (ll i = 1; i <= n; i++) {
if (s[i - 1] == 'R')
pre[1][i]++, a[i] = 1;
if (s[i - 1] == 'G')
pre[2][i]++, a[i] = 2;
if (s[i - 1] == 'B')
pre[3][i]++, a[i] = 3;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= 3; j++)
pre[j][i] += pre[j][i - 1];
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n; j++) {
if (a[i] == a[j])
continue;
ll c = other(a[i], a[j]);
ans += pre[c][i - 1];
ans -= a[2 * i - j] == c;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^・ω・^=)"
#define read_input freopen("in.txt", "r", stdin)
#define print_output freopen("out.txt", "w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
const ll maxn = 4e3 + 10;
ll pre[4][maxn], a[maxn];
ll other(ll a, ll b) {
if (a > b)
swap(a, b);
if (a == 1 && b == 2)
return 3;
if (a == 1 && b == 3)
return 2;
if (a == 2 && b == 3)
return 1;
}
int main() {
ll n;
string s;
cin >> n >> s;
for (ll i = 1; i <= n; i++) {
if (s[i - 1] == 'R')
pre[1][i]++, a[i] = 1;
if (s[i - 1] == 'G')
pre[2][i]++, a[i] = 2;
if (s[i - 1] == 'B')
pre[3][i]++, a[i] = 3;
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= 3; j++)
pre[j][i] += pre[j][i - 1];
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n; j++) {
if (a[i] == a[j])
continue;
ll c = other(a[i], a[j]);
ans += pre[c][i - 1];
if (2 * i - j >= 1 && 2 * i - j <= n)
ans -= a[2 * i - j] == c;
}
}
cout << ans << endl;
return 0;
} | replace | 52 | 53 | 52 | 54 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int N;
string A;
int B[10005];
int pre[10005][5];
long long ans;
int main() {
cin >> N >> A;
for (int i = 0; i < N; i++) {
B[i + 1] = (A[i] == 'R' ? 1 : A[i] == 'G' ? 2 : 3);
pre[i + 1][B[i + 1]] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= 3; j++) {
pre[i][j] += pre[i - 1][j];
}
}
int cari;
for (int i = 1; i = N - 2; i++) {
for (int j = i + 1; j <= N - 1; j++) {
if (B[i] == B[j])
continue;
cari = B[i] ^ B[j];
ans += pre[N][cari] - pre[j][cari] - (B[j + j - i] == cari ? 1 : 0);
}
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int N;
string A;
int B[10005];
int pre[10005][5];
long long ans;
int main() {
cin >> N >> A;
for (int i = 0; i < N; i++) {
B[i + 1] = (A[i] == 'R' ? 1 : A[i] == 'G' ? 2 : 3);
pre[i + 1][B[i + 1]] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= 3; j++) {
pre[i][j] += pre[i - 1][j];
}
}
int cari;
for (int i = 1; i <= N - 2; i++) {
for (int j = i + 1; j <= N - 1; j++) {
if (B[i] == B[j])
continue;
cari = B[i] ^ B[j];
ans += pre[N][cari] - pre[j][cari] - (B[j + j - i] == cari ? 1 : 0);
}
}
cout << ans << "\n";
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02714 | C++ | Runtime Error | /*
PAIN demands to be felt
so do RE, TLE, MLE, SIGSEV & WA
*/
#include <bits/stdc++.h>
using namespace std;
#define CIN \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(), (x).end()
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<std::vector<ll>> matrix;
typedef map<ll, ll> mii;
typedef vector<pii> vpii;
map<char, vi> loc;
ll addd(char c1, char c2, char c3) {
ll n1, n2, n3, n4, ans = 0, i, j;
for (i = 0; i < sz(loc[c1]); i++) {
n1 = loc[c1][i];
n2 = upper_bound(all(loc[c2]), n1) - loc[c2].begin();
n3 = 0;
for (j = n2; j < sz(loc[c2]); j++) {
n2 = loc[c2][j];
n3 = upper_bound(all(loc[c3]), n2) - loc[c3].begin();
n4 = lower_bound(all(loc[c3]), 2 * n2 - n1) - loc[c3].begin();
if (loc[c3][n4] - n2 == n2 - n1)
n3++;
ans += sz(loc[c3]) - n3;
}
}
return ans;
}
void solve() {
ll n = 0, i = 0, ans = 0;
string str;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
cin >> n >> str;
for (i = 0; i < n; i++) {
loc[str[i]].pb(i);
}
//{r , g , b}
ans += addd('R', 'G', 'B');
ans += addd('R', 'B', 'G');
ans += addd('G', 'R', 'B');
ans += addd('G', 'B', 'R');
ans += addd('B', 'R', 'G');
ans += addd('B', 'G', 'R');
cout << ans << endl;
}
int main() {
CIN;
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| /*
PAIN demands to be felt
so do RE, TLE, MLE, SIGSEV & WA
*/
#include <bits/stdc++.h>
using namespace std;
#define CIN \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define sz(x) ((int)((x).size()))
#define all(x) (x).begin(), (x).end()
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<std::vector<ll>> matrix;
typedef map<ll, ll> mii;
typedef vector<pii> vpii;
map<char, vi> loc;
ll addd(char c1, char c2, char c3) {
ll n1, n2, n3, n4, ans = 0, i, j;
if (loc[c2].empty() || loc[c3].empty() || loc[c1].empty())
return 0;
for (i = 0; i < sz(loc[c1]); i++) {
n1 = loc[c1][i];
n2 = upper_bound(all(loc[c2]), n1) - loc[c2].begin();
n3 = 0;
for (j = n2; j < sz(loc[c2]); j++) {
n2 = loc[c2][j];
n3 = upper_bound(all(loc[c3]), n2) - loc[c3].begin();
n4 = lower_bound(all(loc[c3]), 2 * n2 - n1) - loc[c3].begin();
if (loc[c3][n4] - n2 == n2 - n1)
n3++;
ans += sz(loc[c3]) - n3;
}
}
return ans;
}
void solve() {
ll n = 0, i = 0, ans = 0;
string str;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
cin >> n >> str;
for (i = 0; i < n; i++) {
loc[str[i]].pb(i);
}
//{r , g , b}
ans += addd('R', 'G', 'B');
ans += addd('R', 'B', 'G');
ans += addd('G', 'R', 'B');
ans += addd('G', 'B', 'R');
ans += addd('B', 'R', 'G');
ans += addd('B', 'G', 'R');
cout << ans << endl;
}
int main() {
CIN;
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| insert | 30 | 30 | 30 | 32 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int main() {
int n;
cin >> n;
string s;
cin >> s;
long long sum = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; k++) {
if ((j - i) == (k - j) || s[j] == s[k] || s[i] == s[k])
continue;
else
sum++;
}
}
}
cout << sum << endl;
return 0;
}
| #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
int main() {
int n;
cin >> n;
string s;
cin >> s;
long long sum = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; k++) {
if ((j - i) == (k - j) || s[j] == s[k] || s[i] == s[k])
continue;
else
sum++;
}
}
}
cout << sum << endl;
return 0;
}
| insert | 0 | 0 | 0 | 3 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
std::map<int, int> r;
std::map<int, int> g;
std::map<int, int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
r.emplace(i + 1, 1);
} else if (s[i] == 'G') {
g.emplace(i + 1, 1);
} else {
b.emplace(i + 1, 1);
}
}
long long int sum = r.size() * g.size() * b.size();
long long int count = 0;
for (auto itr = r.begin(); itr != r.end(); itr++) {
for (int i = 1; i < n; i++) {
if (g[itr->first + i] == 1 && b[itr->first + i + i] == 1) {
count++;
// cout<<itr->first<<" "<<itr->first+i<<" "<<itr->first+i+i<<endl;
}
if (g[itr->first + i] == 1 && b[itr->first - i] == 1) {
count++;
}
if (g[itr->first - i] == 1 && b[itr->first + i] == 1) {
count++;
}
if (g[itr->first - i] == 1 && b[itr->first - i - i] == 1) {
count++;
// cout<<itr->first<<" "<<itr->first-i<<" "<<itr->first-i-i<<endl;
}
if (g[itr->first - i - i] == 1 && b[itr->first - i] == 1) {
count++;
}
if (g[itr->first + i + i] == 1 && b[itr->first + i] == 1) {
count++;
}
}
}
cout << sum - count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
std::map<int, int> r;
std::map<int, int> g;
std::map<int, int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
r.emplace(i + 1, 1);
} else if (s[i] == 'G') {
g.emplace(i + 1, 1);
} else {
b.emplace(i + 1, 1);
}
}
long long int sum = r.size() * g.size() * b.size();
long long int count = 0;
for (auto itr = r.begin(); itr != r.end(); itr++) {
for (int i = 1; abs(itr->first - i - i) <= n; i++) {
if (g[itr->first + i] == 1 && b[itr->first + i + i] == 1) {
count++;
// cout<<itr->first<<" "<<itr->first+i<<" "<<itr->first+i+i<<endl;
}
if (g[itr->first + i] == 1 && b[itr->first - i] == 1) {
count++;
}
if (g[itr->first - i] == 1 && b[itr->first + i] == 1) {
count++;
}
if (g[itr->first - i] == 1 && b[itr->first - i - i] == 1) {
count++;
// cout<<itr->first<<" "<<itr->first-i<<" "<<itr->first-i-i<<endl;
}
if (g[itr->first - i - i] == 1 && b[itr->first - i] == 1) {
count++;
}
if (g[itr->first + i + i] == 1 && b[itr->first + i] == 1) {
count++;
}
}
}
cout << sum - count << endl;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define PI (2 * acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) \
for (int fi = 0; fi < v.size(); fi++) \
cout << v[fi] << " "; \
cout << endl;
#define showpair(v) \
for (int fi = 0; fi < v.size(); fi++) \
cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan \
for (i = 0; i < n; i++) { \
cin >> in; \
v.pb(in); \
}
#define all(a) a.begin(), a.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mem(a, val) memset(a, val, sizeof(a))
#define loop(i, n) for (i = 0; i < n; i++)
#define TC() \
ull T; \
cin >> T; \
while (T--)
#define IN(x) \
{ scanf("%d", &x); }
#define LL(x) \
{ scanf("%lld", &x); }
#define CC(x) \
{ scanf("%c", &x); }
#define pfl(x) printf("%d\n", x)
#define pfll(x) printf("%lld\n", x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
int main() {
int i = 0, j = 0, cs = 0, in;
int n;
cin >> n;
string s;
cin >> s;
vi arr[3];
for (i = 0; i < s.size(); i++) {
if (s[i] == 'R')
arr[0].pb(i);
else if (s[i] == 'G')
arr[1].pb(i);
else
arr[2].pb(i);
}
ll sum = 0;
for (i = 0; i < s.size(); i++) {
for (j = i + 1; j < s.size(); j++) {
if (s[i] == s[j])
continue;
int x = -1;
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
x = 2;
else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
x = 1;
else
x = 0;
auto it = up(all(arr[x]), j);
sum += (arr[x].end() - it);
it = lb(all(arr[x]), j + (j - i));
if (*it == (j + (j - i)))
sum--;
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
#define PI (2 * acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) \
for (int fi = 0; fi < v.size(); fi++) \
cout << v[fi] << " "; \
cout << endl;
#define showpair(v) \
for (int fi = 0; fi < v.size(); fi++) \
cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan \
for (i = 0; i < n; i++) { \
cin >> in; \
v.pb(in); \
}
#define all(a) a.begin(), a.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mem(a, val) memset(a, val, sizeof(a))
#define loop(i, n) for (i = 0; i < n; i++)
#define TC() \
ull T; \
cin >> T; \
while (T--)
#define IN(x) \
{ scanf("%d", &x); }
#define LL(x) \
{ scanf("%lld", &x); }
#define CC(x) \
{ scanf("%c", &x); }
#define pfl(x) printf("%d\n", x)
#define pfll(x) printf("%lld\n", x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
int main() {
int i = 0, j = 0, cs = 0, in;
int n;
cin >> n;
string s;
cin >> s;
vi arr[3];
for (i = 0; i < s.size(); i++) {
if (s[i] == 'R')
arr[0].pb(i);
else if (s[i] == 'G')
arr[1].pb(i);
else
arr[2].pb(i);
}
ll sum = 0;
for (i = 0; i < s.size(); i++) {
for (j = i + 1; j < s.size(); j++) {
if (s[i] == s[j])
continue;
int x = -1;
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
x = 2;
else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
x = 1;
else
x = 0;
auto it = up(all(arr[x]), j);
sum += (arr[x].end() - it);
it = lb(all(arr[x]), j + (j - i));
if (it != arr[x].end() && *it == (j + (j - i)))
sum--;
}
}
cout << sum << endl;
return 0;
}
| replace | 88 | 89 | 88 | 89 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> v[3];
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
v[0].push_back(i);
if (s[i] == 'G')
v[1].push_back(i);
if (s[i] == 'B')
v[2].push_back(i);
}
auto check = [&](vector<int> a, vector<int> b, vector<int> c) {
long long aa = 0;
for (int l : a) {
for (int m : b) {
if (m < l)
continue;
int d = m - l;
int pos = upper_bound(c.begin(), c.end(), m) - c.begin();
int cur = lower_bound(c.begin(), c.end(), m + d) - c.begin();
aa += c.size() - pos;
if (c[cur] == m + d)
aa--;
}
}
return aa;
};
long long ans = 0;
vector<int> bb = {0, 1, 2};
do {
ans += check(v[bb[0]], v[bb[1]], v[bb[2]]);
} while (next_permutation(bb.begin(), bb.end()));
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> v[3];
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
v[0].push_back(i);
if (s[i] == 'G')
v[1].push_back(i);
if (s[i] == 'B')
v[2].push_back(i);
}
auto check = [&](vector<int> a, vector<int> b, vector<int> c) {
long long aa = 0;
for (int l : a) {
for (int m : b) {
if (m < l)
continue;
int d = m - l;
int pos = upper_bound(c.begin(), c.end(), m) - c.begin();
int cur = lower_bound(c.begin(), c.end(), m + d) - c.begin();
aa += c.size() - pos;
if (cur < (int)c.size() and c[cur] == m + d)
aa--;
}
}
return aa;
};
long long ans = 0;
vector<int> bb = {0, 1, 2};
do {
ans += check(v[bb[0]], v[bb[1]], v[bb[2]]);
} while (next_permutation(bb.begin(), bb.end()));
cout << ans << "\n";
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02714 | Python | Time Limit Exceeded | N = int(input())
S = input()
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
k = j + (j - i)
if N - 1 < k:
continue
if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
ans -= 1
print(ans)
| N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
k = j + (j - i)
if N - 1 < k:
continue
if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
ans -= 1
print(ans)
| replace | 1 | 3 | 1 | 2 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long N;
string s;
int main() {
cin >> N;
cin >> s;
long long total = 0;
for (int i = 0; i <= N - 3; i++) {
for (int j = i + 1; j <= N - 2; j++) {
if (s[i] == s[j]) {
continue;
}
for (int k = j + 1; k <= N - 1; k++) {
if (s[k] != s[j] && s[k] != s[i]) {
if (k - j != j - i) {
total++;
}
}
}
}
}
cout << total << '\n';
} | #include <bits/stdc++.h>
using namespace std;
long long N;
string s;
int main() {
cin >> N;
cin >> s;
long long r = 0, g = 0, b = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'R') {
r++;
} else if (s[i] == 'G') {
g++;
} else {
b++;
}
}
long long total = r * g * b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
long long X = 2 * j - i;
if (X < N) {
if (s[i] != s[j] && s[j] != s[X] && s[i] != s[X]) {
total--;
}
}
}
}
cout << total << '\n';
} | replace | 7 | 18 | 7 | 24 | TLE | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
; \
for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
long long cnt = 0;
for (int i = 0; i < n - 3; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] != s[j]) {
for (int k = j + 1; k < n; k++) {
if (s[j] != s[k] && s[k] != s[i] && (j - i) != (k - j))
cnt++;
}
}
}
}
cout << cnt << endl;
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) \
; \
for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
cin >> n;
string st;
int s[n];
cin >> st;
rep(i, n) {
if (st[i] == 'R')
s[i] = 0;
else if (st[i] == 'G')
s[i] = 1;
else
s[i] = 2;
}
long long cnt = 0;
for (int i = 0; i < n - 3; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] != s[j]) {
for (int k = j + 1; k < n; k++) {
if (s[j] != s[k] && s[k] != s[i] && (j - i) != (k - j))
cnt++;
}
}
}
}
cout << cnt << endl;
} | replace | 16 | 18 | 16 | 27 | TLE | |
p02714 | Python | Time Limit Exceeded | n = int(input())
s = input()
rr = 0
gg = 0
bb = 0
for i in range(n):
if s[i] == "R":
rr += 1
if s[i] == "G":
gg += 1
if s[i] == "B":
bb += 1
ans = rr * gg * bb
for i in range(n):
for j in range(n):
if j - i >= 0 and j + i < n:
if s[j - i] != s[j] and s[j] != s[j + i] and s[j + i] != s[j - i]:
ans -= 1
print(ans)
| n = int(input())
s = input()
rr = 0
gg = 0
bb = 0
for i in range(n):
if s[i] == "R":
rr += 1
if s[i] == "G":
gg += 1
if s[i] == "B":
bb += 1
ans = rr * gg * bb
for j in range(n):
for i in range(min(j + 1, n - j)):
if s[j - i] != s[j] and s[j] != s[j + i] and s[j + i] != s[j - i]:
ans -= 1
print(ans)
| replace | 15 | 20 | 15 | 19 | TLE | |
p02714 | Python | Time Limit Exceeded | N = int(input())
S = input()
# N = 39
# S = 'RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB'
n_R = S.count("R")
n_G = S.count("G")
n_B = S.count("B")
ans = n_R * n_G * n_B
for a in range(N - 2):
# a = 2
for b in range(1, N // 2 + 1):
# b = 3
i = a
j = a + b
k = a + 2 * b
if k > N - 1:
continue
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans)
| N = int(input())
S = input()
# N = 39
# S = 'RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB'
n_R = S.count("R")
n_G = S.count("G")
n_B = S.count("B")
ans = n_R * n_G * n_B
for b in range(1, N // 2 + 1):
# b = 2
for a in range(N - 2 * b):
# a = 1
i = a
j = a + b
k = a + 2 * b
if k > N - 1:
continue
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans)
| replace | 11 | 15 | 11 | 15 | TLE | |
p02714 | Python | Runtime Error | from collections import Counter
from copy import copy
n = int(input())
s = input()
total_cnt = dict(Counter(s))
cnt = [total_cnt]
for i, c in enumerate(s):
curr_cnt = copy(cnt[-1])
curr_cnt[c] -= 1
cnt.append(curr_cnt)
res = 0
for i, c1 in enumerate(s):
for j in range(i + 1, n - 1):
c2 = s[j]
if c2 == c1:
continue
for c3 in "RGB":
if c3 == c1 or c3 == c2:
continue
res += cnt[j + 1][c3]
k = 2 * j - i
if k >= n:
continue
if s[k] == c3:
res -= 1
print(res)
| from collections import Counter
from copy import copy
n = int(input())
s = input()
total_cnt = dict(Counter(s))
if len(total_cnt) < 3:
print(0)
exit()
cnt = [total_cnt]
for i, c in enumerate(s):
curr_cnt = copy(cnt[-1])
curr_cnt[c] -= 1
cnt.append(curr_cnt)
res = 0
for i, c1 in enumerate(s):
for j in range(i + 1, n - 1):
c2 = s[j]
if c2 == c1:
continue
for c3 in "RGB":
if c3 == c1 or c3 == c2:
continue
res += cnt[j + 1][c3]
k = 2 * j - i
if k >= n:
continue
if s[k] == c3:
res -= 1
print(res)
| insert | 7 | 7 | 7 | 11 | 0 | |
p02714 | Python | Runtime Error | import sys
from collections import Counter
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10**9 + 7
INF = float("inf")
def main():
N = int(input())
S = input()
C = Counter(S)
r = C.get("R")
g = C.get("G")
b = C.get("B")
answer = r * g * b
for left in range(N):
for mid in range(left + 1, N):
right = mid * 2 - left
if right < N:
if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
answer -= 1
print(answer)
if __name__ == "__main__":
main()
| import sys
from collections import Counter
def input():
return sys.stdin.readline().strip()
sys.setrecursionlimit(20000000)
MOD = 10**9 + 7
INF = float("inf")
def main():
N = int(input())
S = input()
C = Counter(S)
r = C.get("R", 0)
g = C.get("G", 0)
b = C.get("B", 0)
answer = r * g * b
for left in range(N):
for mid in range(left + 1, N):
right = mid * 2 - left
if right < N:
if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
answer -= 1
print(answer)
if __name__ == "__main__":
main()
| replace | 18 | 21 | 18 | 21 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
string S;
cin >> N;
cin >> S;
vector<int64_t> R, G, B;
for (int64_t i = 0LL; i < N; i++) {
if (S.at(i) == 'R') {
R.push_back(i);
}
if (S.at(i) == 'G') {
G.push_back(i);
}
if (S.at(i) == 'B') {
B.push_back(i);
}
}
int64_t r = R.size();
int64_t g = G.size();
int64_t b = B.size();
int64_t Ans = r * g * b;
int64_t Max, Middle, Min;
for (int64_t i = 0LL; i < r; i++) {
for (int64_t j = 0LL; j < g; j++) {
for (int64_t k = 0LL; k < b; k++) {
Max = max(R.at(i), max(G.at(j), B.at(k)));
Min = min(R.at(i), min(G.at(j), B.at(k)));
Middle = R.at(i) + G.at(j) + B.at(k) - Max - Min;
if (Max - Middle == Middle - Min) {
Ans--;
}
}
}
}
cout << Ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N;
string S;
cin >> N;
cin >> S;
vector<int64_t> R, G, B;
for (int64_t i = 0LL; i < N; i++) {
if (S.at(i) == 'R') {
R.push_back(i);
}
if (S.at(i) == 'G') {
G.push_back(i);
}
if (S.at(i) == 'B') {
B.push_back(i);
}
}
int64_t r = R.size();
int64_t g = G.size();
int64_t b = B.size();
int64_t Ans = r * g * b;
int64_t Max, Middle, Min;
for (int64_t i = 0LL; i < r; i++) {
for (int64_t j = 1LL; j <= (N - R.at(i) - 1) / 2; j++) {
if (S.at(R.at(i) + j) == 'G' && S.at(R.at(i) + 2 * j) == 'B') {
Ans--;
}
if (S.at(R.at(i) + j) == 'B' && S.at(R.at(i) + 2 * j) == 'G') {
Ans--;
}
}
}
for (int64_t i = 0LL; i < g; i++) {
for (int64_t j = 1LL; j <= (N - G.at(i) - 1) / 2; j++) {
if (S.at(G.at(i) + j) == 'B' && S.at(G.at(i) + 2 * j) == 'R') {
Ans--;
}
if (S.at(G.at(i) + j) == 'R' && S.at(G.at(i) + 2 * j) == 'B') {
Ans--;
}
}
}
for (int64_t i = 0LL; i < b; i++) {
for (int64_t j = 1LL; j <= (N - B.at(i) - 1) / 2; j++) {
if (S.at(B.at(i) + j) == 'R' && S.at(B.at(i) + 2 * j) == 'G') {
Ans--;
}
if (S.at(B.at(i) + j) == 'G' && S.at(B.at(i) + 2 * j) == 'R') {
Ans--;
}
}
}
cout << Ans << endl;
} | replace | 26 | 34 | 26 | 52 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll r = 0, g = 0, b = 0, ans = 0;
for (ll i = 0; i < n - 2; ++i) {
for (ll j = i + 1; j < n - 1; ++j) {
for (ll k = j + 1; k < n; ++k) {
if ((s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) &&
(j - i != k - j)) {
ans++;
}
}
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll r = 0, g = 0, b = 0, ans = 0;
for (ll i = 0; i < n; ++i) {
if (s[i] == 'R')
r++;
else if (s[i] == 'G')
g++;
else
b++;
}
ans = r * g * b;
for (ll i = 0; i < n; ++i) {
for (ll j = 1; j <= n; ++j) {
ll kanta = i;
ll kanta1 = i + j;
ll kanta2 = kanta1 + j;
if (kanta2 < n) {
if (s[kanta] != s[kanta2] && s[kanta] != s[kanta1] &&
s[kanta1] != s[kanta2]) {
ans--;
}
}
}
}
cout << ans;
return 0;
}
| replace | 12 | 18 | 12 | 30 | TLE | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#include <bits/stdc++.h>
int main() {
int n;
string s;
cin >> n >> s;
long res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (s[i] == s[j])
continue;
for (int k = 0; k < j; k++)
if (j - k != i - j && s[k] != s[i] && s[k] != s[j])
res++;
}
}
cout << res;
return 0;
} | #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#include <bits/stdc++.h>
int main() {
int n;
string s;
cin >> n >> s;
long res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (s[i] == s[j])
continue;
for (int k = 0; k < j; k++)
if (j - k != i - j && s[k] != s[i] && s[k] != s[j])
res++;
}
}
cout << res;
return 0;
} | insert | 0 | 0 | 0 | 1 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (S.at(i) != S.at(j)) {
int x = j - i;
for (int k = j + 1; k < N; k++) {
if (S.at(i) != S.at(k) && S.at(j) != S.at(k) && x != (k - j)) {
ans++;
}
}
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
string s;
cin >> n >> s;
long long r = 0, g = 0, b = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == 'R')
r++;
else if (s[i] == 'G')
g++;
else if (s[i] == 'B')
b++;
}
long long ans = r * g * b;
for (long long i = 0; i <= n; i++) {
for (long long d = 0; d < n; d++) {
long long j = i + d, k = j + d;
if (k >= n)
break;
if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
ans--;
}
}
cout << ans << endl;
}
| replace | 4 | 18 | 4 | 24 | TLE | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
typedef long long ll;
ll n;
char s[4444];
ll SR[4444], SB[4444], SG[4444];
ll Out;
int main() {
scanf("%lld", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
SR[i] = SR[i - 1];
SB[i] = SB[i - 1];
SG[i] = SG[i - 1];
if (s[i] == 'R')
SR[i]++;
else if (s[i] == 'B')
SB[i]++;
else
SG[i]++;
}
for (int i = 1; i < n - 1; i++) {
for (int j = i + 1; j <= n - 1; j++) {
int Dis = j - i;
if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
Out += (SG[n] - SG[j]);
if (s[j + Dis] == 'G')
Out--;
} else if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
Out += (SB[n] - SB[j]);
if (s[j + Dis] == 'B')
Out--;
} else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
Out += (SR[n] - SR[j]);
if (s[j + Dis] == 'R')
Out--;
}
}
}
printf("%lld\n", Out);
return 0;
} | #include <algorithm>
#include <cstdio>
typedef long long ll;
ll n;
char s[444444];
ll SR[444444], SB[444444], SG[444444];
ll Out;
int main() {
scanf("%lld", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
SR[i] = SR[i - 1];
SB[i] = SB[i - 1];
SG[i] = SG[i - 1];
if (s[i] == 'R')
SR[i]++;
else if (s[i] == 'B')
SB[i]++;
else
SG[i]++;
}
for (int i = 1; i < n - 1; i++) {
for (int j = i + 1; j <= n - 1; j++) {
int Dis = j - i;
if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
Out += (SG[n] - SG[j]);
if (s[j + Dis] == 'G')
Out--;
} else if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
Out += (SB[n] - SB[j]);
if (s[j + Dis] == 'B')
Out--;
} else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
Out += (SR[n] - SR[j]);
if (s[j + Dis] == 'R')
Out--;
}
}
}
printf("%lld\n", Out);
return 0;
} | replace | 5 | 7 | 5 | 7 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
char c;
vector<int> R, G, B;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> c;
switch (c) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
}
}
long long ans = 0;
int m, r, g, b, big, small;
int target[3];
int from, to;
int flag = 0;
for (int i = 0; i < R.size(); i++) {
r = R.at(i);
for (int j = 0; j < G.size(); j++) {
g = G.at(j);
if (r > g) {
big = r;
small = g;
} else {
big = g;
small = r;
}
if ((r + g) % 2) {
target[0] = -1;
} else {
target[0] = (r + g) / 2;
}
target[1] = 2 * big - small;
target[2] = 2 * small - big;
flag = 0;
for (int k = 0; k < 3; k++) {
// if(target[k]<0) continue;
from = 0;
to = B.size() - 1;
while (1) {
if (B.at((to + from) / 2) == target[k]) {
flag++;
break;
} else if (to - from < 1) {
break;
} else if (B.at((to + from) / 2) > target[k]) {
to = (to + from) / 2;
} else {
from = (to + from + 1) / 2;
}
}
}
ans += B.size() - flag;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
char c;
vector<int> R, G, B;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> c;
switch (c) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
}
}
long long ans = 0;
int m, r, g, b, big, small;
int target[3];
int from, to;
int flag = 0;
for (int i = 0; i < R.size(); i++) {
r = R.at(i);
for (int j = 0; j < G.size(); j++) {
g = G.at(j);
if (r > g) {
big = r;
small = g;
} else {
big = g;
small = r;
}
if ((r + g) % 2) {
target[0] = -1;
} else {
target[0] = (r + g) / 2;
}
target[1] = 2 * big - small;
target[2] = 2 * small - big;
flag = 0;
for (int k = 0; k < 3; k++) {
// if(target[k]<0) continue;
from = 0;
to = B.size() - 1;
if (to < 0)
break;
while (1) {
if (B.at((to + from) / 2) == target[k]) {
flag++;
break;
} else if (to - from < 1) {
break;
} else if (B.at((to + from) / 2) > target[k]) {
to = (to + from) / 2;
} else {
from = (to + from + 1) / 2;
}
}
}
ans += B.size() - flag;
}
}
cout << ans;
return 0;
} | insert | 49 | 49 | 49 | 51 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
int fg(int k) {
int sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
signed main() {
int a;
string b;
cin >> a >> b;
int x = 0;
int y = 0;
int z = 0;
rep(i, a) {
if (b.at(i) == 'R') {
x++;
}
if (b.at(i) == 'G') {
y++;
}
if (b.at(i) == 'B') {
z++;
}
}
int sum = x * y * z;
rep1(j, (a - 3) / 2) {
for (int k = 0; k <= a - j * 2; k++) {
if (b.at(k) != b.at(k + j) && b.at(k) != b.at(k + j * 2) &&
b.at(k + j) != b.at(k + j * 2)) {
sum--;
}
}
}
cout << sum;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
int fg(int k) {
int sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
signed main() {
int a;
string b;
cin >> a >> b;
int x = 0;
int y = 0;
int z = 0;
rep(i, a) {
if (b.at(i) == 'R') {
x++;
}
if (b.at(i) == 'G') {
y++;
}
if (b.at(i) == 'B') {
z++;
}
}
int sum = x * y * z;
rep1(j, (a - 3) / 2 + 1) {
for (int k = 0; k < a - j * 2; k++) {
if (b.at(k) != b.at(k + j) && b.at(k) != b.at(k + j * 2) &&
b.at(k + j) != b.at(k + j * 2)) {
sum--;
}
}
}
cout << sum;
}
| replace | 53 | 55 | 53 | 55 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<int>;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define Sort(a) sort(a.begin(), a.end())
#define gSort(a) sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)
const int INF = 2147483647;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
for (int i = 0; i < n - 2; ++i) {
for (int j = i + 1; j < n - 1; ++j) {
for (int k = j + 1; k < n; ++k) {
if (j - i == k - j)
continue;
if ((s[i] != s[j]) && (s[i] != s[k]) && (s[j] != s[k]))
++ans;
}
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<int>;
#define rep(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define Sort(a) sort(a.begin(), a.end())
#define gSort(a) sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)
const int INF = 2147483647;
const ll MOD = 1000000007;
int main() {
int n;
cin >> n;
string s;
cin >> s;
ll r = 0, g = 0, b = 0;
for (auto i : s) {
if (i == 'R')
r++;
else if (i == 'G')
g++;
else
b++;
}
// 全パターンを計上
ll ans = r * g * b;
for (int i = 0; i < n; ++i) {
// 同間隔で条件を満たすなら除く
for (int d = 0; d < n; ++d) {
int j = i + d;
int k = j + d;
if (k >= n)
break;
if ((s[i] != s[j]) && (s[j] != s[k]) && (s[i] != s[k]))
--ans;
}
}
cout << ans;
} | replace | 22 | 31 | 22 | 46 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> R, B, G;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
R.push_back(i + 1);
} else if (s[i] == 'B') {
B.push_back(i + 1);
} else {
G.push_back(i + 1);
}
}
int cnt = 0;
for (int i = 0; i < R.size(); i++) {
for (int k = 0; k < B.size(); k++) {
for (int t = 0; t < G.size(); t++) {
int I, J, K;
I = min({R[i], B[k], G[t]});
K = max({R[i], B[k], G[t]});
J = R[i] + B[k] + G[t] - (I + K);
if (J - I != K - J) {
cnt++;
}
}
}
}
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> R, B, G;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
R.push_back(i + 1);
} else if (s[i] == 'B') {
B.push_back(i + 1);
} else {
G.push_back(i + 1);
}
}
long long cnt = R.size() * B.size() * G.size();
;
for (int i = 0; i < n; i++) {
for (int k = 1; k < n; k++) {
int I, J, K;
long long a = i;
long long b = i + k;
long long c = b + k;
if (c < n) {
if (s[a] != s[b] && s[a] != s[c] && s[b] != s[c]) {
cnt--;
}
}
}
}
cout << cnt << endl;
return 0;
} | replace | 18 | 29 | 18 | 29 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
long long R = 0;
long long G = 0;
long long B = 0;
long long sum = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == 'R') {
R = R + 1;
} else if (S.at(i) == 'G') {
G = G + 1;
} else {
B = B + 1;
}
}
sum = R * G * B;
long long count = 0;
if (N < 3) {
cout << 0 << endl;
} else {
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int m = 2 * j - i;
if ((S.at(i) != S.at(j)) && (S.at(i) != S.at(m)) &&
(S.at(m) != S.at(j))) {
count = count + 1;
}
}
}
cout << sum - count << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
long long R = 0;
long long G = 0;
long long B = 0;
long long sum = 0;
for (int i = 0; i < N; i++) {
if (S.at(i) == 'R') {
R = R + 1;
} else if (S.at(i) == 'G') {
G = G + 1;
} else {
B = B + 1;
}
}
sum = R * G * B;
long long count = 0;
if (N < 3) {
cout << 0 << endl;
} else {
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int m = 2 * j - i;
if (m < N) {
if ((S.at(i) != S.at(j)) && (S.at(i) != S.at(m)) &&
(S.at(m) != S.at(j))) {
count = count + 1;
}
}
}
}
cout << sum - count << endl;
}
} | replace | 28 | 31 | 28 | 33 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02714 | Python | Time Limit Exceeded | def main():
N = int(input())
S = input()
cnt = 0
for i in range(N):
for j in range(i + 1, N):
for k in range(j + 1, N):
if j - i == k - j:
if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
cnt += 1
print(S.count("R") * S.count("B") * S.count("G") - cnt)
if __name__ == "__main__":
main()
| def main():
N = int(input())
S = input()
cnt = 0
for i in range(N):
for j in range(i + 1, N):
k = 2 * j - i
if k >= N:
continue
if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
cnt += 1
print(S.count("R") * S.count("B") * S.count("G") - cnt)
if __name__ == "__main__":
main()
| replace | 6 | 10 | 6 | 11 | TLE | |
p02714 | Python | Time Limit Exceeded | n = int(input())
s = input()
ans = 0
for i in range(len(s)):
one = s[i]
for j in range(i + 1, len(s)):
if s[j] == one:
continue
dis1 = j - i
two = s[j]
for k in range(j + 1, len(s)):
if s[k] == one or s[k] == two:
continue
else:
dis2 = k - j
if dis1 != dis2:
ans += 1
print(ans)
| n = int(input())
s = input()
ans = s.count("R") * s.count("G") * s.count("B")
for i in range(n):
for j in range(i + 1, n):
k = 2 * j - i
# 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
if (
k < n
and (s[i] != s[j] and s[j] != s[k] and s[i] != s[k])
and j - i == k - j
):
ans -= 1
print(ans)
| replace | 2 | 17 | 2 | 15 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n;
string s;
vector<int> v[3];
int idx(int b, int a, int i) { // 在 v[b] 中寻找第一个不小于 v[a][i] 的下标
return upper_bound(v[b].begin(), v[b].end(), v[a][i]) - v[b].begin();
}
ll cal(int a, int b, int c) {
ll ret = 0;
for (int i = 0; i < v[a].size(); i++) {
for (int j = idx(b, a, i); j < v[b].size(); j++) {
for (int k = idx(c, b, j); k < v[c].size(); k++) {
if (v[b][j] - v[a][i] !=
v[c][k] - v[b][j]) { // 等价于条件中的 j - i != k - j
++ret;
}
}
}
}
return ret;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) { // 存储不同字母的位置
if (s[i] == 'R')
v[0].push_back(i);
else if (s[i] == 'G')
v[1].push_back(i);
else
v[2].push_back(i);
}
ll ans = 0;
for (int i = 0; i < 3; i++) { // 枚举RGB的前后情况
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (i != j && i != k && j != k) {
ans += cal(i, j, k);
}
}
}
}
cout << ans;
}
| #include <bits/stdc++.h>
using ll = long long;
using namespace std;
int n;
string s;
vector<int> v[3];
inline int idx(int b, int a,
int i) { // 在 v[b] 中寻找第一个不小于 v[a][i] 的下标
return upper_bound(v[b].begin(), v[b].end(), v[a][i]) - v[b].begin();
}
ll cal(int a, int b, int c) {
ll ret = 0;
for (int i = 0; i < v[a].size(); i++) {
for (int j = idx(b, a, i); j < v[b].size(); j++) {
for (int k = idx(c, b, j); k < v[c].size(); k++) {
if (v[b][j] - v[a][i] !=
v[c][k] - v[b][j]) { // 等价于条件中的 j - i != k - j
++ret;
}
}
}
}
return ret;
}
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) { // 存储不同字母的位置
if (s[i] == 'R')
v[0].push_back(i);
else if (s[i] == 'G')
v[1].push_back(i);
else
v[2].push_back(i);
}
ll ans = 0;
for (int i = 0; i < 3; i++) { // 枚举RGB的前后情况
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (i != j && i != k && j != k) {
ans += cal(i, j, k);
}
}
}
}
cout << ans;
}
| replace | 8 | 9 | 8 | 10 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
using namespace std;
const int N = 1e3 + 7;
const int INF = 1e18;
const int mod = 1e9 + 7;
int R[N], G[N], B[N], n;
string s;
int check(int k, char c) {
if (k >= n) {
return 0;
}
return (s[k] == c);
}
int32_t main() {
speed;
cin >> n;
cin >> s;
for (int i = n - 1; i >= 0; i--) {
R[i] += R[i + 1];
G[i] += G[i + 1];
B[i] += B[i + 1];
if (s[i] == 'R') {
R[i]++;
}
if (s[i] == 'G') {
G[i]++;
}
if (s[i] == 'B') {
B[i]++;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j]) {
continue;
}
int d = j - i;
int k = j + d;
if (j + 1 >= n) {
continue;
}
if (s[i] == 'R' && s[j] == 'G') {
ans += B[j + 1];
ans -= check(k, 'B');
}
if (s[i] == 'R' && s[j] == 'B') {
ans += G[j + 1];
ans -= check(k, 'G');
}
if (s[i] == 'G' && s[j] == 'R') {
ans += B[j + 1];
ans -= check(k, 'B');
}
if (s[i] == 'G' && s[j] == 'B') {
ans += R[j + 1];
ans -= check(k, 'R');
}
if (s[i] == 'B' && s[j] == 'R') {
ans += G[j + 1];
ans -= check(k, 'G');
}
if (s[i] == 'B' && s[j] == 'G') {
ans += R[j + 1];
ans -= check(k, 'R');
}
// for ( int k = j + 1; k < n; k++ ) {
// if ( j - i == k - j || s[i] == s[j] || s[i] == s[k] || s[j] ==
// s[k] ) { continue;
// }
// ans++;
// }
}
}
cout << ans;
} | #include <bits/stdc++.h>
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define int long long
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e18;
const int mod = 1e9 + 7;
int R[N], G[N], B[N], n;
string s;
int check(int k, char c) {
if (k >= n) {
return 0;
}
return (s[k] == c);
}
int32_t main() {
speed;
cin >> n;
cin >> s;
for (int i = n - 1; i >= 0; i--) {
R[i] += R[i + 1];
G[i] += G[i + 1];
B[i] += B[i + 1];
if (s[i] == 'R') {
R[i]++;
}
if (s[i] == 'G') {
G[i]++;
}
if (s[i] == 'B') {
B[i]++;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j]) {
continue;
}
int d = j - i;
int k = j + d;
if (j + 1 >= n) {
continue;
}
if (s[i] == 'R' && s[j] == 'G') {
ans += B[j + 1];
ans -= check(k, 'B');
}
if (s[i] == 'R' && s[j] == 'B') {
ans += G[j + 1];
ans -= check(k, 'G');
}
if (s[i] == 'G' && s[j] == 'R') {
ans += B[j + 1];
ans -= check(k, 'B');
}
if (s[i] == 'G' && s[j] == 'B') {
ans += R[j + 1];
ans -= check(k, 'R');
}
if (s[i] == 'B' && s[j] == 'R') {
ans += G[j + 1];
ans -= check(k, 'G');
}
if (s[i] == 'B' && s[j] == 'G') {
ans += R[j + 1];
ans -= check(k, 'R');
}
// for ( int k = j + 1; k < n; k++ ) {
// if ( j - i == k - j || s[i] == s[j] || s[i] == s[k] || s[j] ==
// s[k] ) { continue;
// }
// ans++;
// }
}
}
cout << ans;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<int> RED;
vector<int> GR;
vector<int> BLUE;
rep(i, S.size()) {
if (S[i] == 'R') {
RED.push_back(i);
} else if (S[i] == 'G') {
GR.push_back(i);
} else {
BLUE.push_back(i);
}
}
long long res = 0;
for (auto r : RED) {
for (auto g : GR) {
for (auto b : BLUE) {
if (abs(r - g) == abs(g - b) || abs(r - b) == abs(b - g) ||
abs(g - r) == abs(r - b))
continue;
res++;
}
}
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<int> RED;
vector<int> GR;
vector<int> BLUE;
rep(i, S.size()) {
if (S[i] == 'R') {
RED.push_back(i);
} else if (S[i] == 'G') {
GR.push_back(i);
} else {
BLUE.push_back(i);
}
}
long long res = 0;
// for(auto r : RED) {
// for(auto g : GR) {
// // for(auto b : BLUE) {
// // if (abs(r-g) == abs(g-b) || abs(r-b) == abs(b-g) || abs(g-
// r) == abs(r-b)) continue;
// // res++;
// // }
// int diff = abs(r-g);
// }
// }
res += RED.size() * BLUE.size() * GR.size();
// cout << res << endl;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (j + j - i >= N)
continue;
if (S[i] != S[j] && S[i] != S[j + j - i] && S[j] != S[j + j - i]) {
// cout << i << j;
res--;
}
}
}
cout << res << endl;
return 0;
}
| replace | 21 | 28 | 21 | 40 | TLE | |
p02714 | Python | Runtime Error | def main():
from collections import Counter
n, s = int(input()), input()
c = Counter(s)
d = list(c.values())
ans = d[0] * d[1] * d[2]
rgb = {"R", "G", "B"}
for i in range(1, n // 2 + 1):
for j in range(i):
x = s[j::i]
for a, b, c in zip(x, x[1:], x[2:]):
g = {a, b, c}
if g == rgb:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
| def main():
from collections import Counter
n, s = int(input()), input()
c = Counter(s)
d = list(c.values())
if len(d) < 3:
print(0)
exit()
ans = d[0] * d[1] * d[2]
rgb = {"R", "G", "B"}
for i in range(1, n // 2 + 1):
for j in range(i):
x = s[j::i]
for a, b, c in zip(x, x[1:], x[2:]):
g = {a, b, c}
if g == rgb:
ans -= 1
print(ans)
if __name__ == "__main__":
main()
| replace | 6 | 7 | 6 | 9 | 0 | |
p02714 | Python | Time Limit Exceeded | n = int(input())
s = list(input())
tot = 0
R = [i for i, x in enumerate(s) if x == "R"]
G = [i for i, x in enumerate(s) if x == "G"]
B = [i for i, x in enumerate(s) if x == "B"]
tot += len(R) * len(G) * len(B)
for i in range(len(R)):
for j in range(len(G)):
for k in range(len(B)):
if (
2 * R[i] == G[j] + B[k]
or 2 * G[j] == R[i] + B[k]
or 2 * B[k] == G[j] + R[i]
):
tot -= 1
print(tot)
| n = int(input())
s = list(input())
tot = 0
tot += s.count("R") * s.count("G") * s.count("B")
for i in range(n):
for j in range(i + 1, n):
k = 2 * j - i
if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
tot -= 1
print(tot)
| replace | 3 | 16 | 3 | 9 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0, sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI = acos(-1.0L);
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
// GCD,LCMを求める関数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
signed main() {
int n;
cin >> n;
string s;
cin >> s;
VI r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.PB(i);
if (s[i] == 'G')
g.PB(i);
if (s[i] == 'B')
b.PB(i);
}
int ans = r.size() * g.size() * b.size();
VI idx(3);
rep(i, r.size()) {
rep(j, g.size()) {
rep(k, b.size()) {
idx[0] = r[i];
idx[1] = g[j];
idx[2] = b[k];
sort(RALL(idx));
if (idx[0] - idx[1] == idx[1] - idx[2])
ans--;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9 + 7)
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPS(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0, sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI = acos(-1.0L);
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
// GCD,LCMを求める関数
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
signed main() {
int n;
cin >> n;
string s;
cin >> s;
VI r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.PB(i);
if (s[i] == 'G')
g.PB(i);
if (s[i] == 'B')
b.PB(i);
}
ll ans = r.size() * g.size() * b.size();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int k = 2 * j - i;
if (k >= n)
continue;
if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
ans--;
}
}
cout << ans << endl;
return 0;
}
| replace | 56 | 68 | 56 | 65 | TLE | |
p02714 | Python | Time Limit Exceeded | N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
if S[i] != S[j]:
x = 2 * j - i
if x <= N - 1 and S[i] != S[x] and S[x] != S[j]:
ans -= 1
print(ans)
| N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
if S[i] != S[j]:
x = 2 * j - i
if x < N and S[i] != S[x] and S[x] != S[j]:
ans -= 1
print(ans)
| replace | 8 | 9 | 8 | 9 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
int ans = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (a[i] != a[j]) {
for (int k = j + 1; k < n; k++) {
if (a[k] != a[i] && a[k] != a[j] && k + i != 2 * j)
ans++;
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
long long int r = 0, g = 0, b = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 'R')
r++;
else if (a[i] == 'G')
g++;
else
b++;
}
long long int ans = r * g * b;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int k = 2 * j - i;
if (k >= n)
continue;
if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i])
ans--;
}
}
cout << ans << endl;
return 0;
}
| replace | 8 | 17 | 8 | 25 | TLE | |
p02714 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map<int, int>
#define mll map<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vd vector<double>
#define vll vector<ll>
#define fi first
#define se second
#define si set<int>
#define sll set<ll>
#define spii set<pii>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vvi vector<vector<int>>
#define vvpii vector<vector<pii>>
#define vvll vector<vll>
#define vsi vector<si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
const ll INFLL = 1e18;
const int MAXN = 400 + 100;
const ll INF = 1e9;
const ll mod1 = 1e9 + 7;
const ll mod2 = 2e9 + 11;
int R[MAXN], B[MAXN], G[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("a.in", "r", stdin);
#endif
int n;
cin >> n;
string s;
cin >> s;
int r = 0, b = 0, g = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r++;
if (s[i] == 'B')
b++;
if (s[i] == 'G')
g++;
R[i + 1] = r;
B[i + 1] = b;
G[i + 1] = g;
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
if (s[i] != 'B' && s[j] != 'B') {
ans += B[n] - B[j];
if (j + j - i < n && s[2 * j - i] == 'B')
ans--;
}
if (s[i] != 'G' && s[j] != 'G') {
ans += G[n] - G[j];
if (j + j - i < n && s[2 * j - i] == 'G')
ans--;
}
if (s[i] != 'R' && s[j] != 'R') {
ans += R[n] - R[j];
if (j + j - i < n && s[2 * j - i] == 'R')
ans--;
}
}
}
cout << ans;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map<int, int>
#define mll map<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vd vector<double>
#define vll vector<ll>
#define fi first
#define se second
#define si set<int>
#define sll set<ll>
#define spii set<pii>
#define vs vector<string>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long, long long>>
#define vvi vector<vector<int>>
#define vvpii vector<vector<pii>>
#define vvll vector<vll>
#define vsi vector<si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
const ll INFLL = 1e18;
const int MAXN = 4000 + 100;
const ll INF = 1e9;
const ll mod1 = 1e9 + 7;
const ll mod2 = 2e9 + 11;
int R[MAXN], B[MAXN], G[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("a.in", "r", stdin);
#endif
int n;
cin >> n;
string s;
cin >> s;
int r = 0, b = 0, g = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r++;
if (s[i] == 'B')
b++;
if (s[i] == 'G')
g++;
R[i + 1] = r;
B[i + 1] = b;
G[i + 1] = g;
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
if (s[i] != 'B' && s[j] != 'B') {
ans += B[n] - B[j];
if (j + j - i < n && s[2 * j - i] == 'B')
ans--;
}
if (s[i] != 'G' && s[j] != 'G') {
ans += G[n] - G[j];
if (j + j - i < n && s[2 * j - i] == 'G')
ans--;
}
if (s[i] != 'R' && s[j] != 'R') {
ans += R[n] - R[j];
if (j + j - i < n && s[2 * j - i] == 'R')
ans--;
}
}
}
cout << ans;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cout << setprecision(10) << fixed;
int n;
string s;
cin >> n >> s;
vector<int> a[3];
map<char, int> mp = {{'R', 0}, {'G', 1}, {'B', 2}};
for (int i = 0; i < n; ++i) {
a[mp[s[i]]].push_back(i);
}
long long ans = 0;
for (int i = 0; i < a[0].size(); ++i) {
for (int j = 0; j < a[1].size(); ++j) {
for (int k = 0; k < a[2].size(); ++k) {
vector<int> b = {a[0][i], a[1][j], a[2][k]};
sort(b.begin(), b.end());
if (b[1] - b[0] == b[2] - b[1])
continue;
ans++;
}
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cout << setprecision(10) << fixed;
int n;
string s;
cin >> n >> s;
vector<int> a[3];
map<char, int> mp = {{'R', 0}, {'G', 1}, {'B', 2}};
for (int i = 0; i < n; ++i) {
a[mp[s[i]]].push_back(i);
}
long long ans = 0;
for (int i = 0; i < a[0].size(); ++i) {
for (int j = 0; j < a[1].size(); ++j) {
ans += (a[2].size());
int x = max(a[0][i], a[1][j]);
int y = min(a[0][i], a[1][j]);
int diff = x - y;
if (x + diff < n && s[x + diff] == 'B')
ans--;
if (y - diff >= 0 && s[y - diff] == 'B')
ans--;
if ((x + y) % 2 == 0 && s[(x + y) / 2] == 'B')
ans--;
}
}
cout << ans;
return 0;
}
| replace | 17 | 24 | 17 | 27 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.emplace_back(i);
else if (s[i] == 'G')
g.emplace_back(i);
else if (s[i] == 'B')
b.emplace_back(i);
}
ll ans = (ll)r.size() * g.size() * b.size();
for (int i : r)
for (int j : g)
for (int k : b) {
int a = abs(i - j);
int b = abs(j - k);
int c = abs(k - i);
if (a == b || b == c || c == a)
ans--;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.emplace_back(i);
else if (s[i] == 'G')
g.emplace_back(i);
else if (s[i] == 'B')
b.emplace_back(i);
}
ll ans = (ll)r.size() * g.size() * b.size();
for (int i = 0; i < n - 2; i++)
for (int j = i + 1; j < n - 1; j++) {
if (j + j - i >= n)
continue;
if (s[i] == s[j] || s[i] == s[j + j - i] || s[j] == s[j + j - i])
continue;
else
ans--;
}
cout << ans << endl;
return 0;
} | replace | 24 | 33 | 24 | 33 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
vector<int> r, g, b;
char s[4005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r.pb(i);
else if (s[i] == 'G')
g.pb(i);
else
b.pb(i);
}
int sr = r.size(), sg = g.size(), sb = b.size();
ll ans = sr * sg * sb;
for (int i = 0; i < sr; i++) {
for (int j = 0; j < sg; j++) {
int L = r[i], R = g[j];
int d = R - L;
if (d % 2 == 0 && s[L + d / 2] == 'B')
ans--;
if (L - d > 0 && s[L - d] == 'B')
ans--;
if (R + d < n && s[R + d] == 'B')
ans--;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
vector<int> r, g, b;
char s[4005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r.pb(i);
else if (s[i] == 'G')
g.pb(i);
else
b.pb(i);
}
int sr = r.size(), sg = g.size(), sb = b.size();
ll ans = (ll)sr * sg * sb;
for (int d = 1; d <= n; d++) {
for (int a = 0; a + d + d < n; a++) {
if (s[a] != s[a + d] && s[a] != s[a + d + d] && s[a + d] != s[a + d + d])
ans--;
}
}
cout << ans << endl;
return 0;
}
| replace | 21 | 31 | 21 | 25 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
typedef long long ll;
using namespace std;
int main() {
int n;
ll ans = 0;
string s;
cin >> n >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r.push_back(i + 1);
if (s[i] == 'G')
g.push_back(i + 1);
if (s[i] == 'B')
b.push_back(i + 1);
}
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
for (int k = 0; k < b.size(); k++) {
if (max(r[i], max(g[j], b[k])) -
(r[i] + g[j] + b[k] - max(r[i], max(g[j], b[k])) -
min(r[i], min(g[j], b[k]))) !=
-min(r[i], min(g[j], b[k])) +
(r[i] + g[j] + b[k] - max(r[i], max(g[j], b[k])) -
min(r[i], min(g[j], b[k])))) {
ans++;
}
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
typedef long long ll;
using namespace std;
int main() {
int n;
ll ans = 0;
string s;
cin >> n >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r.push_back(i + 1);
if (s[i] == 'G')
g.push_back(i + 1);
if (s[i] == 'B')
b.push_back(i + 1);
}
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
ans += b.size();
int big = max(r[i], g[j]);
int small = min(r[i], g[j]);
int sa = big - small;
if (binary_search(b.begin(), b.end(), big + sa)) {
ans -= 1;
}
if (binary_search(b.begin(), b.end(), small - sa)) {
ans -= 1;
}
if (sa % 2 == 0) {
if (binary_search(b.begin(), b.end(), small + sa / 2)) {
ans -= 1;
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 31 | 39 | 31 | 44 | TLE | |
p02714 | Python | Time Limit Exceeded | #!/usr/bin/env python3
def main():
N = int(input())
S = input()
ans = 0
for i in range(N):
for j in range(i, N):
for k in range(j, N):
if (
1
and S[i] != S[j]
and S[i] != S[k]
and S[j] != S[k]
and j - i != k - j
):
ans += 1
print(ans)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
def main():
N = int(input())
S = input()
res = 0
R, G, B = S.count("R"), S.count("G"), S.count("B")
for i in range(N - 2):
for j in range(i + 1, N - 1):
k = j + j - i
if k >= N:
continue
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
res += 1
print(R * G * B - res)
if __name__ == "__main__":
main()
| replace | 5 | 18 | 5 | 15 | TLE | |
p02715 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define FOR(x, b, e) for (int x = (b); x <= (e); ++x)
#define FORD(x, b, e) for (int x = ((int)(b)) - 1; x >= (e); --x)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(c) c.begin(), c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
typedef short int sint;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it) {
*this << ((it != d.b) ? ", " : "") << *it;
}
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int mod = 1000000000 + 7;
vector<ll> results;
ll result;
ll pot(ll a, int b) {
ll res = 1;
while (b) {
if (b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
result = 0;
results.resize(n + 1, 0);
FORD(x, k + 1, 1) {
int nums = k / x;
results[x] = pot(nums, n);
for (int j = 2 * x; j <= k; j += x) {
results[x] = (results[x] - results[j] + mod) % mod;
}
result = (result + results[x] * x) % mod;
}
cout << result << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
#define FOR(x, b, e) for (int x = (b); x <= (e); ++x)
#define FORD(x, b, e) for (int x = ((int)(b)) - 1; x >= (e); --x)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ALL(c) c.begin(), c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
typedef short int sint;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it) {
*this << ((it != d.b) ? ", " : "") << *it;
}
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int mod = 1000000000 + 7;
vector<ll> results;
ll result;
ll pot(ll a, int b) {
ll res = 1;
while (b) {
if (b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
result = 0;
results.resize(k + 1, 0);
FORD(x, k + 1, 1) {
int nums = k / x;
results[x] = pot(nums, n);
for (int j = 2 * x; j <= k; j += x) {
results[x] = (results[x] - results[j] + mod) % mod;
}
result = (result + results[x] * x) % mod;
}
cout << result << endl;
} | replace | 89 | 90 | 89 | 90 | 0 | |
p02715 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 500010;
ll modpow(ll a, ll n, ll mod) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
int main() {
ll n, k, ans = 0;
cin >> n >> k;
vector<ll> g(n + 2);
for (ll m = k; m >= 1; m--) {
ll kata = 1;
while (m * (kata + 1) <= k)
kata++;
g[m] = modpow(kata, n, MOD) % MOD;
for (ll i = 2; m * i <= k; i++) {
g[m] -= g[m * i];
g[m] %= MOD;
}
}
for (int i = 1; i <= k; i++) {
// cout<<i<<" "<<g[i]<<endl;
ans += i * g[i];
ans %= MOD;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 500010;
ll modpow(ll a, ll n, ll mod) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
int main() {
ll n, k, ans = 0;
cin >> n >> k;
vector<ll> g(k + 2);
for (ll m = k; m >= 1; m--) {
ll kata = 1;
while (m * (kata + 1) <= k)
kata++;
g[m] = modpow(kata, n, MOD) % MOD;
for (ll i = 2; m * i <= k; i++) {
g[m] -= g[m * i];
g[m] %= MOD;
}
}
for (int i = 1; i <= k; i++) {
// cout<<i<<" "<<g[i]<<endl;
ans += i * g[i];
ans %= MOD;
}
cout << ans << endl;
return 0;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define Pii pair<int, int>
#define Pid pair<int, double>
#define Pdd pair<double, double>
#define MOD 1000000007
#define EPS 0.00000001
#define N_MAX 100000
using namespace std;
int powmod(int x, int y) {
int ret = 1;
REP(_, y) ret = (ret * x) % MOD;
return ret;
}
int gcd(int x, int y) {
if (x > y)
swap(x, y);
while (true) {
y = y % x;
if (y == 0)
return x;
swap(x, y);
}
}
signed main() {
int n, k;
int ans = 0;
cin >> n >> k;
vector<int> a(k);
REP(i, k) { a[i] = k / (i + 1); }
vector<int> b(k);
REP(i, k) {
int idx = k - 1 - i;
REP(j, a[idx] - 1) {
b[idx] = (b[idx] - b[(j + 2) * (idx + 1) - 1] + MOD) % MOD;
}
b[idx] = (b[idx] + powmod(a[idx], n)) % MOD;
}
REP(i, k) {
// cout << b[i] << "\n";
ans = (ans + b[i] * (i + 1)) % MOD;
}
cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
#define Pii pair<int, int>
#define Pid pair<int, double>
#define Pdd pair<double, double>
#define MOD 1000000007
#define EPS 0.00000001
#define N_MAX 100000
using namespace std;
int powmod(int x, int y) {
int ret = 1;
while (y > 0) {
if (y & 1)
ret = (ret * x) % MOD;
x = (x * x) % MOD;
y >>= 1;
}
return ret % MOD;
}
int gcd(int x, int y) {
if (x > y)
swap(x, y);
while (true) {
y = y % x;
if (y == 0)
return x;
swap(x, y);
}
}
signed main() {
int n, k;
int ans = 0;
cin >> n >> k;
vector<int> a(k);
REP(i, k) { a[i] = k / (i + 1); }
vector<int> b(k);
REP(i, k) {
int idx = k - 1 - i;
REP(j, a[idx] - 1) {
b[idx] = (b[idx] - b[(j + 2) * (idx + 1) - 1] + MOD) % MOD;
}
b[idx] = (b[idx] + powmod(a[idx], n)) % MOD;
}
REP(i, k) {
// cout << b[i] << "\n";
ans = (ans + b[i] * (i + 1)) % MOD;
}
cout << ans << "\n";
return 0;
} | replace | 22 | 24 | 22 | 29 | TLE | |
p02715 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
const ll mod = 1000000007;
const int N = 200010;
ll fact[N], invf[N];
ll add(ll x, ll y) { return (x + y) % mod; }
ll mul(ll x, ll y) { return (x % mod) * (y % mod) % mod; }
ll powll(ll x, ll y) {
x %= mod;
ll res = 1LL;
while (y) {
if (y & 1LL)
res *= x;
res %= mod;
x = (x * x) % mod;
y >>= 1LL;
}
return res;
}
ll divll(ll x, ll y) {
x %= mod;
return (x * powll(y, mod - 2)) % mod;
}
ll nPr(ll n, ll r) {
if (n < r || r < 0)
return 0;
return mul(fact[n], invf[n - r]);
}
ll nCr(ll n, ll r) {
if (n < r || r < 0)
return 0;
return mul(mul(fact[n], invf[r]), invf[n - r]);
}
void init_f() {
fact[0] = 1;
FOR(i, 1, N - 1) { fact[i] = (fact[i - 1] * i) % mod; }
invf[N - 1] = divll(1, fact[N - 1]);
FORR(i, N - 1, 1) { invf[i - 1] = (invf[i] * i) % mod; }
}
int main(void) {
ll n, k;
cin >> n >> k;
VL cnt(n + 1);
FORR(d, k, 1) {
ll c = k / d;
ll all = powll(c, n);
for (ll e = 2 * d; e <= k; e += d) {
all = (all + mod - cnt[e]) % mod;
}
cnt[d] = all;
}
ll ans = 0;
FOR(d, 1, k) ans = (ans + cnt[d] * d) % mod;
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
const ll mod = 1000000007;
const int N = 200010;
ll fact[N], invf[N];
ll add(ll x, ll y) { return (x + y) % mod; }
ll mul(ll x, ll y) { return (x % mod) * (y % mod) % mod; }
ll powll(ll x, ll y) {
x %= mod;
ll res = 1LL;
while (y) {
if (y & 1LL)
res *= x;
res %= mod;
x = (x * x) % mod;
y >>= 1LL;
}
return res;
}
ll divll(ll x, ll y) {
x %= mod;
return (x * powll(y, mod - 2)) % mod;
}
ll nPr(ll n, ll r) {
if (n < r || r < 0)
return 0;
return mul(fact[n], invf[n - r]);
}
ll nCr(ll n, ll r) {
if (n < r || r < 0)
return 0;
return mul(mul(fact[n], invf[r]), invf[n - r]);
}
void init_f() {
fact[0] = 1;
FOR(i, 1, N - 1) { fact[i] = (fact[i - 1] * i) % mod; }
invf[N - 1] = divll(1, fact[N - 1]);
FORR(i, N - 1, 1) { invf[i - 1] = (invf[i] * i) % mod; }
}
int main(void) {
ll n, k;
cin >> n >> k;
VL cnt(k + 1);
FORR(d, k, 1) {
ll c = k / d;
ll all = powll(c, n);
for (ll e = 2 * d; e <= k; e += d) {
all = (all + mod - cnt[e]) % mod;
}
cnt[d] = all;
}
ll ans = 0;
FOR(d, 1, k) ans = (ans + cnt[d] * d) % mod;
cout << ans << endl;
return 0;
}
| replace | 101 | 102 | 101 | 102 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a, ll b) {
if (b > a)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll rep_jijo(ll n, ll x) {
if (x == 0)
return 1;
if (x % 2 == 0) {
ll t = rep_jijo(n, x / 2);
return t * t % mod;
}
return n * rep_jijo(n, x - 1) % mod;
}
ll com(ll n, ll r) {
ll x = 1, y = 1;
ll tmp = n;
while (tmp >= n - r + 1) {
x = x * tmp % mod;
tmp--;
}
while (r > 0) {
y = y * r % mod;
r--;
}
return x * rep_jijo(y, mod - 2) % mod;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> d(K);
d[K - 1] = 1;
for (ll i = K; i > 0; i--) {
ll sum = 0;
for (ll j = 2 * i; j <= K; j += i) {
sum += d[j - 1];
}
ll z = 1;
ll tmp = N;
ll x = K / i;
while (tmp > 0) {
z *= x;
z %= mod;
tmp--;
}
d[i - 1] = z - sum;
}
ll ans = 0;
rep(i, K) {
ans += d[i] * (i + 1);
ans %= mod;
}
cout << ans % mod << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a, ll b) {
if (b > a)
swap(a, b);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll rep_jijo(ll n, ll x) {
if (x == 0)
return 1;
if (x % 2 == 0) {
ll t = rep_jijo(n, x / 2);
return t * t % mod;
}
return n * rep_jijo(n, x - 1) % mod;
}
ll com(ll n, ll r) {
ll x = 1, y = 1;
ll tmp = n;
while (tmp >= n - r + 1) {
x = x * tmp % mod;
tmp--;
}
while (r > 0) {
y = y * r % mod;
r--;
}
return x * rep_jijo(y, mod - 2) % mod;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> d(K);
d[K - 1] = 1;
for (ll i = K; i > 0; i--) {
ll sum = 0;
for (ll j = 2 * i; j <= K; j += i) {
sum += d[j - 1];
}
ll z = rep_jijo(K / i, N);
d[i - 1] = z - sum;
}
ll ans = 0;
rep(i, K) {
ans += d[i] * (i + 1);
ans %= mod;
}
cout << ans % mod << endl;
return 0;
}
| replace | 54 | 63 | 54 | 55 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
// #define DEBUG
#ifdef DEBUG
using std::endl;
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#endif // DEBUG
#ifndef DEBUG
using namespace std;
#endif // DEBUG
template <class T> void print_vect(T v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
}
int gcd(int a, int b) {
if (a < b) {
return gcd(b, a);
} else {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
}
uint64_t pow(uint64_t a, uint64_t p, uint64_t mod) {
if (p < 2) {
uint64_t ans = 1;
while (p--) {
ans = (ans * a) % mod;
}
return ans;
} else {
if (p % 2) {
uint64_t ans = pow(a, p / 2, mod);
uint64_t real_ans = (ans * ans) % mod;
real_ans = (real_ans * a) % mod;
return real_ans;
} else {
uint64_t ans = pow(a, p / 2, mod);
return (ans * ans) % mod;
}
}
}
uint64_t count_turple(uint64_t N, uint64_t K) {
std::vector<uint64_t> count_gcd(K + 1, 0);
const uint64_t MOD = 1000000007;
count_gcd[K] = 1;
for (uint64_t j = K - 1; j >= 1; j--) {
uint64_t fist_count = pow(K / j, N, MOD);
// cout << "first count " << fist_count << endl;
uint64_t multiple = 2;
while (j <= K / multiple) {
fist_count = (fist_count + MOD - count_gcd[multiple * j]) % MOD;
multiple++;
}
count_gcd[j] = fist_count;
// cout << "count gcd = " << j << " -> " << fist_count << endl;
}
uint64_t ans = 0;
for (uint64_t i = 1; i <= K; i++) {
ans = (ans + count_gcd[i] * i) % MOD;
}
return ans;
}
bool func_to_create() {
uint64_t N, K;
cin >> N >> K;
uint64_t ans = count_turple(N, K);
cout << ans << endl;
}
int main() {
// making data IO Fast
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
/***************************/
#ifdef DEBUG
int TEST_CASES = 3;
while (TEST_CASES--) {
#endif // DEBBUG
func_to_create();
#ifdef DEBUG
}
#endif // DEBUG
return 0;
}
| #include <bits/stdc++.h>
// #define DEBUG
#ifdef DEBUG
using std::endl;
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#endif // DEBUG
#ifndef DEBUG
using namespace std;
#endif // DEBUG
template <class T> void print_vect(T v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
cout << endl;
}
int gcd(int a, int b) {
if (a < b) {
return gcd(b, a);
} else {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
}
uint64_t pow(uint64_t a, uint64_t p, uint64_t mod) {
if (p < 2) {
uint64_t ans = 1;
while (p--) {
ans = (ans * a) % mod;
}
return ans;
} else {
if (p % 2) {
uint64_t ans = pow(a, p / 2, mod);
uint64_t real_ans = (ans * ans) % mod;
real_ans = (real_ans * a) % mod;
return real_ans;
} else {
uint64_t ans = pow(a, p / 2, mod);
return (ans * ans) % mod;
}
}
}
uint64_t count_turple(uint64_t N, uint64_t K) {
std::vector<uint64_t> count_gcd(K + 1, 0);
const uint64_t MOD = 1000000007;
count_gcd[K] = 1;
for (uint64_t j = K - 1; j >= 1; j--) {
uint64_t fist_count = pow(K / j, N, MOD);
// cout << "first count " << fist_count << endl;
uint64_t multiple = 2;
while (j <= K / multiple) {
fist_count = (fist_count + MOD - count_gcd[multiple * j]) % MOD;
multiple++;
}
count_gcd[j] = fist_count;
// cout << "count gcd = " << j << " -> " << fist_count << endl;
}
uint64_t ans = 0;
for (uint64_t i = 1; i <= K; i++) {
ans = (ans + count_gcd[i] * i) % MOD;
}
return ans;
}
void func_to_create() {
uint64_t N, K;
cin >> N >> K;
uint64_t ans = count_turple(N, K);
cout << ans << endl;
}
int main() {
// making data IO Fast
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
/***************************/
#ifdef DEBUG
int TEST_CASES = 3;
while (TEST_CASES--) {
#endif // DEBBUG
func_to_create();
#ifdef DEBUG
}
#endif // DEBUG
return 0;
}
| replace | 73 | 74 | 73 | 74 | 0 | |
p02715 | Python | Time Limit Exceeded | from collections import defaultdict
N, K = [int(i) for i in input().split()]
mod = 10**9 + 7
dd = defaultdict(int)
ans = 0
for i in range(K, 0, -1):
dd[i] = (K // i) ** N
for temp in range(i * 2, K + 1, i):
dd[i] -= dd[temp]
ans += dd[i] * i
ans %= mod
print(ans)
| from collections import defaultdict
N, K = [int(i) for i in input().split()]
mod = 10**9 + 7
dd = defaultdict(int)
ans = 0
for i in range(K, 0, -1):
dd[i] = pow(K // i, N, mod)
for temp in range(i * 2, K + 1, i):
dd[i] -= dd[temp]
ans += dd[i] * i
ans %= mod
print(ans)
| replace | 8 | 9 | 8 | 9 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
int pw(int a, int b, int m = MOD) {
if (b == 0)
return 1;
if (b & 1)
return a * pw(a, b - 1) % m;
return pw(a * a % m, b / 2);
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> ans(n + 1);
int pans = 0;
for (int i = k; i >= 1; i--) {
ans[i] = pw(k / i, n);
for (int j = 2; j * i <= k; j++) {
ans[i] = (ans[i] - ans[i * j] + MOD) % MOD;
}
pans = (pans + ans[i] * i % MOD) % MOD;
}
cout << pans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
int pw(int a, int b, int m = MOD) {
if (b == 0)
return 1;
if (b & 1)
return a * pw(a, b - 1) % m;
return pw(a * a % m, b / 2);
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> ans(k + 1);
int pans = 0;
for (int i = k; i >= 1; i--) {
ans[i] = pw(k / i, n);
for (int j = 2; j * i <= k; j++) {
ans[i] = (ans[i] - ans[i * j] + MOD) % MOD;
}
pans = (pans + ans[i] * i % MOD) % MOD;
}
cout << pans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mo = 1000000007;
ll modpow(ll a, ll n, ll mod) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
ll MOD(ll a, ll mod) {
ll temp = a % mod;
if (temp < 0)
temp += mod;
return temp;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> dp(N + 1, 0);
for (ll i = K; i >= 1; i--) {
ll temp = modpow(K / i, N, mo);
ll b = 2 * i;
while (b <= K) {
temp = MOD(temp - dp[b] % mo, mo);
b += i;
}
dp[i] = temp;
}
ll sum = 0;
for (ll i = 0; i <= K; i++) {
sum = (sum + dp[i] * i % mo) % mo;
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mo = 1000000007;
ll modpow(ll a, ll n, ll mod) {
ll ret = 1;
while (n > 0) {
if (n & 1)
ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
ll MOD(ll a, ll mod) {
ll temp = a % mod;
if (temp < 0)
temp += mod;
return temp;
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> dp(K + 1, 0);
for (ll i = K; i >= 1; i--) {
ll temp = modpow(K / i, N, mo);
ll b = 2 * i;
while (b <= K) {
temp = MOD(temp - dp[b] % mo, mo);
b += i;
}
dp[i] = temp;
}
ll sum = 0;
for (ll i = 0; i <= K; i++) {
sum = (sum + dp[i] * i % mo) % mo;
}
cout << sum << endl;
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02715 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
if (former < b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (b < former) {
former = b;
return true;
}
return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v) \
std::sort(v.begin(), v.end(), \
std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\n"; };
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////
ll n, k;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
const ll MOD = 1000000007;
using mint = Fp<MOD>;
typedef mint RUI; // 適当に合わせて.
RUI rui(ll num, ll k) { // num^k
RUI ans = 1;
RUI n = num;
while (k > 0) {
if (k & 1)
ans *= n;
n *= n;
k /= 2;
}
return ans;
}
vector<bool> ck;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(30);
cin >> n >> k;
mint ans = 0;
vector<mint> mem(n + 1);
for (ll i = k; i >= 1; i--) {
ll id = k / i;
mint tmp = rui(id, n);
rep(j, id) {
if (j == 0)
continue;
tmp -= mem[i * (j + 1)];
}
mem[i] = tmp;
mint ii = i;
ans += ii * tmp;
}
print(ans);
return 0;
} | #include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
if (former < b) {
former = b;
return true;
}
return false;
}
template <class T> bool chmin(T &former, const T &b) {
if (b < former) {
former = b;
return true;
}
return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v) \
std::sort(v.begin(), v.end(), \
std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\n"; };
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////
ll n, k;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
const ll MOD = 1000000007;
using mint = Fp<MOD>;
typedef mint RUI; // 適当に合わせて.
RUI rui(ll num, ll k) { // num^k
RUI ans = 1;
RUI n = num;
while (k > 0) {
if (k & 1)
ans *= n;
n *= n;
k /= 2;
}
return ans;
}
vector<bool> ck;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(30);
cin >> n >> k;
mint ans = 0;
vector<mint> mem(k + 1);
for (ll i = k; i >= 1; i--) {
ll id = k / i;
mint tmp = rui(id, n);
rep(j, id) {
if (j == 0)
continue;
tmp -= mem[i * (j + 1)];
}
mem[i] = tmp;
mint ii = i;
ans += ii * tmp;
}
print(ans);
return 0;
} | replace | 142 | 143 | 142 | 143 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
ll num[N + 1];
for (ll i = K; i >= 1; i--) {
num[i] = modpow(K / i, N);
for (ll j = 2; i * j <= K; j++)
num[i] = (num[i] - num[i * j] + MOD) % MOD;
ans = (ans + i * num[i]) % MOD;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
ll ans = 0;
ll num[K + 1];
for (ll i = K; i >= 1; i--) {
num[i] = modpow(K / i, N);
for (ll j = 2; i * j <= K; j++)
num[i] = (num[i] - num[i * j] + MOD) % MOD;
ans = (ans + i * num[i]) % MOD;
}
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long mpow(long long x, int n) {
long long r = 1;
while (n > 0) {
if (n & 1)
r = r * x % 1000000007;
x = x * x % 1000000007;
n >>= 1;
}
return r;
}
int main() {
int n, k;
cin >> n >> k;
long long sumg = 0;
vector<long long> cntg(k);
for (int i = k; 0 < i; i--) {
long long cntb = k / i;
cntg[i] = mpow(cntb, n);
for (int j = 2; j * i <= k; j++) {
cntg[i] += (1000000007 - cntg[j * i]);
cntg[i] %= 1000000007;
if (cntg[i] < 0)
cout << 1;
}
sumg += cntg[i] * i;
sumg %= 1000000007;
}
cout << sumg << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long mpow(long long x, int n) {
long long r = 1;
while (n > 0) {
if (n & 1)
r = r * x % 1000000007;
x = x * x % 1000000007;
n >>= 1;
}
return r;
}
int main() {
int n, k;
cin >> n >> k;
long long sumg = 0;
long long cntg[100010];
for (int i = k; 0 < i; i--) {
long long cntb = k / i;
cntg[i] = mpow(cntb, n);
for (int j = 2; j * i <= k; j++) {
cntg[i] += (1000000007 - cntg[j * i]);
cntg[i] %= 1000000007;
if (cntg[i] < 0)
cout << 1;
}
sumg += cntg[i] * i;
sumg %= 1000000007;
}
cout << sumg << endl;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02715 | Python | Runtime Error | # YouTube解説
MOD = 1000000007
n, k = [int(x) for x in input().split()]
d = [0] * (k + 1)
for i in range(0, k + 1):
d[i] = pow(k // i, n, MOD)
for i in range(k, 0, -1): # 大きいほうから
for j in range(i * 2, k + 1, i): # iの倍数
# d[6] = d'[6] - d[12] - d[18] ...
d[i] -= d[j]
d[i] %= MOD
ans = 0
for i, item in enumerate(d):
ans += i * item
ans %= MOD
print(ans)
| # YouTube解説
MOD = 1000000007
n, k = [int(x) for x in input().split()]
d = [0] * (k + 1)
for i in range(1, k + 1):
d[i] = pow(k // i, n, MOD)
for i in range(k, 0, -1): # 大きいほうから
for j in range(i * 2, k + 1, i): # iの倍数
# d[6] = d'[6] - d[12] - d[18] ...
d[i] -= d[j]
d[i] %= MOD
ans = 0
for i, item in enumerate(d):
ans += i * item
ans %= MOD
print(ans)
| replace | 5 | 6 | 5 | 6 | ZeroDivisionError: integer division or modulo by zero | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02715/Python/s098159754.py", line 7, in <module>
d[i] = pow(k // i, n, MOD)
ZeroDivisionError: integer division or modulo by zero
|
p02715 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
using ll = long long;
ll mypow(ll a, ll b) {
ll res = a;
for (int i = 1; i < b; ++i) {
res = (res * a) % mod;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
ll res = 0;
ll cnt[100001] = {};
for (ll i = K; i > 0; --i) {
cnt[i] += mypow((K / i), N);
for (ll j = 2; j <= K; ++j) {
if (i * j <= K) {
cnt[i] -= cnt[i * j];
} else {
break;
}
}
res += (cnt[i] * i) % mod;
}
res = res % mod;
cout << res;
return 0;
} | #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
using ll = long long;
ll mypow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ll N, K;
cin >> N >> K;
ll res = 0;
ll cnt[100001] = {};
for (ll i = K; i > 0; --i) {
cnt[i] += mypow((K / i), N);
for (ll j = 2; j <= K; ++j) {
if (i * j <= K) {
cnt[i] -= cnt[i * j];
} else {
break;
}
}
res += (cnt[i] * i) % mod;
}
res = res % mod;
cout << res;
return 0;
} | replace | 8 | 11 | 8 | 15 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define each(i, c) for (auto &i : c)
#define mkp(a, b) make_pair(a, b)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
os << "(" << p.first << ": " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
os << "(";
each(i, v) os << i << ", ";
os << ")";
return os;
}
template <typename K, typename V>
ostream &operator<<(ostream &os, map<K, V> m) {
os << "{";
each(i, m) os << i << ", ";
os << "}";
return os;
}
class modint {
private:
ll m_val;
ll m_mod;
public:
constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
constexpr modint(const ll x) : m_val(0), m_mod(0) {
m_mod = MOD;
m_val = x % m_mod;
}
constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) {
m_mod = mod;
m_val = x % m_mod;
}
constexpr ll val() const { return m_val; }
constexpr modint operator+(const modint &rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint &rhs) {
m_val += rhs.m_val;
if (m_val >= m_mod)
m_val -= m_mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) {
if (m_val < rhs.m_val)
m_val += m_mod;
m_val -= rhs.m_val;
return *this;
}
constexpr modint &operator*=(const modint &rhs) {
m_val = m_val * rhs.m_val % m_mod;
return *this;
}
constexpr modint &operator/=(const modint &rhs) {
*this *= rhs.pow(m_mod - 2);
return *this;
}
constexpr modint pow(ll n) const {
if (n == 0)
return 1;
modint o = pow(n >> 1);
o *= o;
if (n & 1)
o *= *this;
return o;
}
friend ostream &operator<<(ostream &os, const modint &a) {
os << a.val();
return os;
}
};
ll modpow(ll x, ll n) {
ll res = 1;
while (n != 0) {
if (n & 1)
res = res * x % MOD;
x = x * x % MOD;
n = n >> 1;
}
return res;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> memo(n + 1);
for (ll i = k; i >= 1; --i) {
ll a = modpow(k / i, n);
memo[i] = a;
for (ll j = 2; i * j <= k; ++j) {
memo[i] -= memo[i * j];
}
}
modint ans(0);
for (ll i = 1; i <= k; ++i) {
ans += (i * memo[i]);
}
cout << ans.val() << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define each(i, c) for (auto &i : c)
#define mkp(a, b) make_pair(a, b)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
template <typename P, typename Q>
ostream &operator<<(ostream &os, pair<P, Q> p) {
os << "(" << p.first << ": " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
os << "(";
each(i, v) os << i << ", ";
os << ")";
return os;
}
template <typename K, typename V>
ostream &operator<<(ostream &os, map<K, V> m) {
os << "{";
each(i, m) os << i << ", ";
os << "}";
return os;
}
class modint {
private:
ll m_val;
ll m_mod;
public:
constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
constexpr modint(const ll x) : m_val(0), m_mod(0) {
m_mod = MOD;
m_val = x % m_mod;
}
constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) {
m_mod = mod;
m_val = x % m_mod;
}
constexpr ll val() const { return m_val; }
constexpr modint operator+(const modint &rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint &rhs) {
m_val += rhs.m_val;
if (m_val >= m_mod)
m_val -= m_mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) {
if (m_val < rhs.m_val)
m_val += m_mod;
m_val -= rhs.m_val;
return *this;
}
constexpr modint &operator*=(const modint &rhs) {
m_val = m_val * rhs.m_val % m_mod;
return *this;
}
constexpr modint &operator/=(const modint &rhs) {
*this *= rhs.pow(m_mod - 2);
return *this;
}
constexpr modint pow(ll n) const {
if (n == 0)
return 1;
modint o = pow(n >> 1);
o *= o;
if (n & 1)
o *= *this;
return o;
}
friend ostream &operator<<(ostream &os, const modint &a) {
os << a.val();
return os;
}
};
ll modpow(ll x, ll n) {
ll res = 1;
while (n != 0) {
if (n & 1)
res = res * x % MOD;
x = x * x % MOD;
n = n >> 1;
}
return res;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> memo(k + 1);
for (ll i = k; i >= 1; --i) {
ll a = modpow(k / i, n);
memo[i] = a;
for (ll j = 2; i * j <= k; ++j) {
memo[i] -= memo[i * j];
}
}
modint ans(0);
for (ll i = 1; i <= k; ++i) {
ans += (i * memo[i]);
}
cout << ans.val() << endl;
return 0;
}
| replace | 108 | 109 | 108 | 109 | 0 | |
p02715 | C++ | Runtime Error | // https://atcoder.jp/contests/abc162/tasks/abc162_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
using mint = ModInt<(int)1e9 + 7>;
// https://www.hamayanhamayan.com/entry/2020/04/12/225411
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<mint> cnt(N + 1);
for (int g = K; g >= 1; g--) {
// ^ は XORではなくpower
cnt[g] = mint(K / g) ^ N;
int gg = g * 2;
while (gg <= K) {
cnt[g] -= cnt[gg];
gg += g;
}
}
mint ans = 0;
FOR(i, 1, K + 1) { ans += cnt[i] * i; }
cout << ans << endl;
return 0;
}
| // https://atcoder.jp/contests/abc162/tasks/abc162_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
using mint = ModInt<(int)1e9 + 7>;
// https://www.hamayanhamayan.com/entry/2020/04/12/225411
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<mint> cnt(K + 1);
for (int g = K; g >= 1; g--) {
// ^ は XORではなくpower
cnt[g] = mint(K / g) ^ N;
int gg = g * 2;
while (gg <= K) {
cnt[g] -= cnt[gg];
gg += g;
}
}
mint ans = 0;
FOR(i, 1, K + 1) { ans += cnt[i] * i; }
cout << ans << endl;
return 0;
}
| replace | 78 | 79 | 78 | 79 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
template <std::uint_fast64_t Modulus> class modint {
// long long から modint
// を作るときは必ず正の数にしてからコンストラクタに入れること!
// そうしないとバグります
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
using mint = modint<mod>;
template <class T, class U> constexpr T power(T x, U exp) {
T ret = static_cast<T>(1);
while (exp) {
if (exp % static_cast<U>(2) == static_cast<U>(1))
ret *= x;
exp /= static_cast<U>(2);
x *= x;
}
return ::std::move(ret);
}
ll N, K;
mint calc(ll x, vector<ll> meb) {
mint res = 0;
for (int i = x; i <= K; i += x) {
mint tmp = 0;
mint val = K / i;
tmp += power(val, N) * mint(-meb[i / x] + mod);
res += tmp;
}
res *= x;
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<ll> is_prime(101010, 1);
vector<ll> meb(101010, -1);
meb[0] = 0;
meb[1] = 0;
is_prime[0] = 0;
is_prime[1] = 0;
ll m = 101000;
REP(i, m) {
if (is_prime[i] == 0)
continue;
for (int j = 2; j * i <= m; j++) {
is_prime[i * j] = 0;
}
for (int j = 1; j * i <= m; j++) {
meb[i * j] *= -1;
if (j % i == 0)
meb[i * j] = 0;
}
}
meb[1] = -1;
cin >> N >> K;
mint res = 0;
for (int i = 1; i <= K; i++) {
mint tmp = calc(i, meb);
res += tmp;
}
cout << res.value() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
template <std::uint_fast64_t Modulus> class modint {
// long long から modint
// を作るときは必ず正の数にしてからコンストラクタに入れること!
// そうしないとバグります
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
constexpr u64 &value() noexcept { return a; }
constexpr const u64 &value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
using mint = modint<mod>;
template <class T, class U> constexpr T power(T x, U exp) {
T ret = static_cast<T>(1);
while (exp) {
if (exp % static_cast<U>(2) == static_cast<U>(1))
ret *= x;
exp /= static_cast<U>(2);
x *= x;
}
return ::std::move(ret);
}
ll N, K;
mint calc(ll x, vector<ll> &meb) {
mint res = 0;
for (int i = x; i <= K; i += x) {
mint tmp = 0;
mint val = K / i;
tmp += power(val, N) * mint(-meb[i / x] + mod);
res += tmp;
}
res *= x;
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<ll> is_prime(101010, 1);
vector<ll> meb(101010, -1);
meb[0] = 0;
meb[1] = 0;
is_prime[0] = 0;
is_prime[1] = 0;
ll m = 101000;
REP(i, m) {
if (is_prime[i] == 0)
continue;
for (int j = 2; j * i <= m; j++) {
is_prime[i * j] = 0;
}
for (int j = 1; j * i <= m; j++) {
meb[i * j] *= -1;
if (j % i == 0)
meb[i * j] = 0;
}
}
meb[1] = -1;
cin >> N >> K;
mint res = 0;
for (int i = 1; i <= K; i++) {
mint tmp = calc(i, meb);
res += tmp;
}
cout << res.value() << endl;
return 0;
}
| replace | 127 | 128 | 127 | 128 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 1e9 + 7;
inline int add(int x, int y) {
ll res = x + y;
while (res >= MOD)
res -= MOD;
return res;
}
inline int mul(int x, int y) { return (1LL * x * y) % MOD; }
int modpow(int x, int p) {
int res = 1;
while (p) {
if (p & 1)
gmul(res, x);
gmul(x, x);
p /= 2;
}
return res;
}
inline int invert(int x) { return modpow(x, MOD - 2); }
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> dp(n + 1);
rep(i, 1, k + 1) {
dp[i] = modpow(i, n);
int la;
for (int x = 2; x <= i; x = la + 1) {
la = min(i / (i / x), i);
gadd(dp[i], MOD - mul(la - x + 1, dp[i / x]));
}
}
int ans = 0;
rep(i, 1, k + 1) { gadd(ans, mul(i, dp[k / i])); }
cout << ans << '\n';
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 1e9 + 7;
inline int add(int x, int y) {
ll res = x + y;
while (res >= MOD)
res -= MOD;
return res;
}
inline int mul(int x, int y) { return (1LL * x * y) % MOD; }
int modpow(int x, int p) {
int res = 1;
while (p) {
if (p & 1)
gmul(res, x);
gmul(x, x);
p /= 2;
}
return res;
}
inline int invert(int x) { return modpow(x, MOD - 2); }
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> dp(k + 1);
rep(i, 1, k + 1) {
dp[i] = modpow(i, n);
int la;
for (int x = 2; x <= i; x = la + 1) {
la = min(i / (i / x), i);
gadd(dp[i], MOD - mul(la - x + 1, dp[i / x]));
}
}
int ans = 0;
rep(i, 1, k + 1) { gadd(ans, mul(i, dp[k / i])); }
cout << ans << '\n';
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02715 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//----------------------- Print Function ----------------------//
inline void print() { cout << '\n'; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
//------------------------- Libraries -------------------------//
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<1000000007>;
//--------------------------- Solve ---------------------------//
void solve() {
int N, K;
cin >> N >> K;
vector<mint> num(N + 1);
mint ans = 0;
for (int i = K; i >= 1; i--) {
mint k = K / i;
mint n = modpow(k, N);
for (int j = 2 * i; j <= K; j += i)
n -= num[j];
num[i] = n;
ans += (mint)i * n;
}
cout << ans << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//----------------------- Print Function ----------------------//
inline void print() { cout << '\n'; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
//------------------------- Libraries -------------------------//
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<1000000007>;
//--------------------------- Solve ---------------------------//
void solve() {
int N, K;
cin >> N >> K;
vector<mint> num(K + 1);
mint ans = 0;
for (int i = K; i >= 1; i--) {
mint k = K / i;
mint n = modpow(k, N);
for (int j = 2 * i; j <= K; j += i)
n -= num[j];
num[i] = n;
ans += (mint)i * n;
}
cout << ans << '\n';
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
} | replace | 84 | 85 | 84 | 85 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
ll mod(ll val, ll m) {
ll res = val % m;
if (res < 0)
res += m;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
vector<int> prime(int x) {
vector<int> ans;
vector<bool> prime(x + 1, true);
prime[0] = prime[1] = false;
rep(i, x + 1) {
if (prime[i]) {
for (int j = i + i; j < x + 1; j += i) {
prime[j] = false;
}
}
}
rep(i, x + 1) {
if (prime[i] == true)
ans.push_back(i);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, K;
cin >> N >> K;
vll a(K + 1);
vll pows(K + 1);
ll p = 1000000007;
REP(i, 1, K + 1) { pows[i] = modpow(K / i, N, p); }
auto primes = prime(K);
ll ans = 0;
vll subs(K + 1);
for (int i = K; i >= 0; i--) {
ll sub = 0;
REP(j, 1, K + 1) {
if (ll(i) * ll(j) > K)
continue;
sub += a[i * j];
// sub += pows[ll(i) * ll(prime)]; //a[ll(i) * ll(prime)] + mod(pows[ll(i)
// * ll(prime)] - a[ll(i) * ll(prime)], p);
sub %= p;
}
a[i] = mod(pows[i] - sub, p);
ans += i * a[i];
subs[i] = sub;
ans %= p;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }
ll mod(ll val, ll m) {
ll res = val % m;
if (res < 0)
res += m;
return res;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
vector<int> prime(int x) {
vector<int> ans;
vector<bool> prime(x + 1, true);
prime[0] = prime[1] = false;
rep(i, x + 1) {
if (prime[i]) {
for (int j = i + i; j < x + 1; j += i) {
prime[j] = false;
}
}
}
rep(i, x + 1) {
if (prime[i] == true)
ans.push_back(i);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, K;
cin >> N >> K;
vll a(K + 1);
vll pows(K + 1);
ll p = 1000000007;
REP(i, 1, K + 1) { pows[i] = modpow(K / i, N, p); }
auto primes = prime(K);
ll ans = 0;
vll subs(K + 1);
for (int i = K; i >= 0; i--) {
ll sub = 0;
REP(j, 1, K + 1) {
if (ll(i) * ll(j) > K)
break;
sub += a[i * j];
// sub += pows[ll(i) * ll(prime)]; //a[ll(i) * ll(prime)] + mod(pows[ll(i)
// * ll(prime)] - a[ll(i) * ll(prime)], p);
sub %= p;
}
a[i] = mod(pows[i] - sub, p);
ans += i * a[i];
subs[i] = sub;
ans %= p;
}
cout << ans << endl;
return 0;
} | replace | 100 | 101 | 100 | 101 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
// #define fi first
// #define se second
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll M = 1000000007ll;
const ll MOD = 1000000007ll;
const ll MAX = 100000001ll;
// const ll M = 1000000000+7;
ll cnt = 0;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
mint powpow(ll a, ll b) {
if (!a)
return 1;
if (b == 0) {
mint xx = 1;
return xx;
}
if (b == 1) {
mint xx = a;
return xx;
}
if (b % 2 == 0) {
mint xx = powpow(a, b / 2);
return xx * xx;
} else {
mint xx = powpow(a, b / 2);
return xx * xx * a;
}
}
mint f(ll n) {
if (n == 0)
return 1;
mint ans = f(n / 2);
ans *= ans;
if (n % 2 == 1)
ans *= 2;
return ans;
}
mint choose(ll n, ll k) {
mint x = 1, y = 1;
rep(i, k) {
x *= (n - i);
y *= (i + 1);
}
return x / y;
}
static bool IsPrime(int n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtNum = sqrt(n);
for (int i = 3; i <= sqrtNum; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
struct BIT {
private:
vector<ll> bit;
ll N;
public:
BIT(ll size) {
N = size;
bit.resize(N + 1);
}
// 一点更新です
void add(ll a, ll w) {
for (ll x = a; x <= N; x += x & -x)
bit[x] += w;
}
// 1~Nまでの和を求める。
int sum(ll a) {
ll ret = 0;
for (ll x = a; x > 0; x -= x & -x)
ret += bit[x];
return ret;
}
};
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(n + 1);
mint ans = powpow(k, n);
rep(i, k) {
ll x = k - i;
// cout<<x<<endl;
mint tmp = powpow((k / x), n);
mint sude = 0;
rep(l, k / x) {
ll j = x * (l + 2);
// cout<<x<<" "<<j<<endl;
if (j <= k) {
sude += v[j];
// cout <<x<<" "<<sude.x<<endl;
}
}
ans += (tmp - sude) * x;
ans -= tmp - sude;
v[x] = ll(tmp.x) - ll(sude.x);
// cout <<tmp.x<<" "<<sude.x<<" "<<v[x]<<endl;
}
// ans += powpow(k, n) - tmp;
cout << ans.x << endl;
// cout<<v[4]<<endl;
}
| #include <bits/stdc++.h>
// #define fi first
// #define se second
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll M = 1000000007ll;
const ll MOD = 1000000007ll;
const ll MAX = 100000001ll;
// const ll M = 1000000000+7;
ll cnt = 0;
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
mint powpow(ll a, ll b) {
if (!a)
return 1;
if (b == 0) {
mint xx = 1;
return xx;
}
if (b == 1) {
mint xx = a;
return xx;
}
if (b % 2 == 0) {
mint xx = powpow(a, b / 2);
return xx * xx;
} else {
mint xx = powpow(a, b / 2);
return xx * xx * a;
}
}
mint f(ll n) {
if (n == 0)
return 1;
mint ans = f(n / 2);
ans *= ans;
if (n % 2 == 1)
ans *= 2;
return ans;
}
mint choose(ll n, ll k) {
mint x = 1, y = 1;
rep(i, k) {
x *= (n - i);
y *= (i + 1);
}
return x / y;
}
static bool IsPrime(int n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtNum = sqrt(n);
for (int i = 3; i <= sqrtNum; i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
struct BIT {
private:
vector<ll> bit;
ll N;
public:
BIT(ll size) {
N = size;
bit.resize(N + 1);
}
// 一点更新です
void add(ll a, ll w) {
for (ll x = a; x <= N; x += x & -x)
bit[x] += w;
}
// 1~Nまでの和を求める。
int sum(ll a) {
ll ret = 0;
for (ll x = a; x > 0; x -= x & -x)
ret += bit[x];
return ret;
}
};
int main() {
ll n, k;
cin >> n >> k;
vector<ll> v(k + 1);
mint ans = powpow(k, n);
rep(i, k) {
ll x = k - i;
// cout<<x<<endl;
mint tmp = powpow((k / x), n);
mint sude = 0;
rep(l, k / x) {
ll j = x * (l + 2);
// cout<<x<<" "<<j<<endl;
if (j <= k) {
sude += v[j];
// cout <<x<<" "<<sude.x<<endl;
}
}
ans += (tmp - sude) * x;
ans -= tmp - sude;
v[x] = ll(tmp.x) - ll(sude.x);
// cout <<tmp.x<<" "<<sude.x<<" "<<v[x]<<endl;
}
// ans += powpow(k, n) - tmp;
cout << ans.x << endl;
// cout<<v[4]<<endl;
}
| replace | 169 | 170 | 169 | 170 | 0 | |
p02715 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; i++)
#define rep3(i, n, m) for (ll i = n; i >= m; i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF = 1e18;
inline void chmax(ll &a, ll b) { a = max(a, b); }
inline void chmin(ll &a, ll b) { a = min(a, b); }
// ミント
const int mod = 1e9 + 7;
// 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// 昆布
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
mint modpow(ll a, ll b) {
if (b == 0)
return 1;
mint c = modpow(a, b / 2);
if (b % 2 == 1)
return c * c * a;
else
return c * c;
}
int main() {
ll n, k;
cin >> n >> k;
mint ans = 0;
vector<mint> B(n + 1);
for (ll i = k; i >= 1; i--) {
ll a = k / i;
mint sum = modpow(a, n);
for (ll p = i * 2; p <= k; p += i) {
sum -= B[p];
}
B[i] = sum;
mint j = i;
ans += sum * j;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; i++)
#define rep3(i, n, m) for (ll i = n; i >= m; i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF = 1e18;
inline void chmax(ll &a, ll b) { a = max(a, b); }
inline void chmin(ll &a, ll b) { a = min(a, b); }
// ミント
const int mod = 1e9 + 7;
// 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// 昆布
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
mint modpow(ll a, ll b) {
if (b == 0)
return 1;
mint c = modpow(a, b / 2);
if (b % 2 == 1)
return c * c * a;
else
return c * c;
}
int main() {
ll n, k;
cin >> n >> k;
mint ans = 0;
vector<mint> B(k + 1);
for (ll i = k; i >= 1; i--) {
ll a = k / i;
mint sum = modpow(a, n);
for (ll p = i * 2; p <= k; p += i) {
sum -= B[p];
}
B[i] = sum;
mint j = i;
ans += sum * j;
}
cout << ans << endl;
return 0;
}
| replace | 92 | 93 | 92 | 93 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ALL(x) begin(x), end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> inline bool chmax(T &a, const T &b) {
return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
sort(begin(v), end(v), f);
v.resize(unique(begin(v), end(v)) - begin(v));
}
// {{{ ModInt
template <int _MOD> struct ModInt {
static const auto MOD = _MOD;
template <class T>
using integral_only = typename enable_if<is_integral<T>::value>::type;
int x;
constexpr ModInt() : x() {}
template <class T, integral_only<T> * = nullptr> ModInt(T _x = 0) {
x = _x % MOD;
if (x < 0)
x += MOD;
}
ModInt operator-() const { return {x == 0 ? 0 : MOD - x}; }
ModInt &operator+=(const ModInt a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(const ModInt a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(const ModInt a) {
x = (long long)x * a.x % MOD;
return *this;
}
ModInt &operator/=(const ModInt a) { return (*this) *= a.inv(); }
ModInt operator+(const ModInt a) const { return ModInt(*this) += a; }
ModInt operator-(const ModInt a) const { return ModInt(*this) -= a; }
ModInt operator*(const ModInt a) const { return ModInt(*this) *= a; }
ModInt operator/(const ModInt a) const { return ModInt(*this) /= a; }
ModInt inv() const {
// for prime MOD
return pow(MOD - 2);
}
ModInt inv2() const {
// work for non-prime MOD if gcd(x,MOD) = 1
int a = x, b = MOD, u = 1, v = 0;
while (b != 0) {
int t = a / b;
a -= t * b;
u -= t * v;
swap(a, b);
swap(u, v);
}
return u;
}
template <class T, integral_only<T> * = nullptr> ModInt pow(T t) const {
ModInt r = 1, p = *this;
while (t) {
if (t & 1)
r *= p;
p *= p;
t >>= 1;
}
return r;
}
bool operator==(ModInt rhs) const { return x == rhs.x; }
bool operator!=(ModInt rhs) const { return x != rhs.x; }
bool operator<(ModInt rhs) const { return x < rhs.x; }
bool operator<=(ModInt rhs) const { return x <= rhs.x; }
bool operator>(ModInt rhs) const { return x > rhs.x; }
bool operator>=(ModInt rhs) const { return x >= rhs.x; }
friend string to_string(ModInt i) { return to_string(i.x); }
friend istream &operator>>(istream &i, ModInt &a) { return i >> a.x; }
friend ostream &operator<<(ostream &o, const ModInt &a) { return o << a.x; }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;
// }}}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<mint> v(n + 1);
mint ans = 0;
for (int i = k; i > 0; i--) {
mint x = k / i;
v[i] = x.pow(n);
for (int j = 2 * i; j <= k; j += i) {
v[i] -= v[j];
}
ans += v[i] * i;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ALL(x) begin(x), end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> inline bool chmax(T &a, const T &b) {
return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
sort(begin(v), end(v), f);
v.resize(unique(begin(v), end(v)) - begin(v));
}
// {{{ ModInt
template <int _MOD> struct ModInt {
static const auto MOD = _MOD;
template <class T>
using integral_only = typename enable_if<is_integral<T>::value>::type;
int x;
constexpr ModInt() : x() {}
template <class T, integral_only<T> * = nullptr> ModInt(T _x = 0) {
x = _x % MOD;
if (x < 0)
x += MOD;
}
ModInt operator-() const { return {x == 0 ? 0 : MOD - x}; }
ModInt &operator+=(const ModInt a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(const ModInt a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(const ModInt a) {
x = (long long)x * a.x % MOD;
return *this;
}
ModInt &operator/=(const ModInt a) { return (*this) *= a.inv(); }
ModInt operator+(const ModInt a) const { return ModInt(*this) += a; }
ModInt operator-(const ModInt a) const { return ModInt(*this) -= a; }
ModInt operator*(const ModInt a) const { return ModInt(*this) *= a; }
ModInt operator/(const ModInt a) const { return ModInt(*this) /= a; }
ModInt inv() const {
// for prime MOD
return pow(MOD - 2);
}
ModInt inv2() const {
// work for non-prime MOD if gcd(x,MOD) = 1
int a = x, b = MOD, u = 1, v = 0;
while (b != 0) {
int t = a / b;
a -= t * b;
u -= t * v;
swap(a, b);
swap(u, v);
}
return u;
}
template <class T, integral_only<T> * = nullptr> ModInt pow(T t) const {
ModInt r = 1, p = *this;
while (t) {
if (t & 1)
r *= p;
p *= p;
t >>= 1;
}
return r;
}
bool operator==(ModInt rhs) const { return x == rhs.x; }
bool operator!=(ModInt rhs) const { return x != rhs.x; }
bool operator<(ModInt rhs) const { return x < rhs.x; }
bool operator<=(ModInt rhs) const { return x <= rhs.x; }
bool operator>(ModInt rhs) const { return x > rhs.x; }
bool operator>=(ModInt rhs) const { return x >= rhs.x; }
friend string to_string(ModInt i) { return to_string(i.x); }
friend istream &operator>>(istream &i, ModInt &a) { return i >> a.x; }
friend ostream &operator<<(ostream &o, const ModInt &a) { return o << a.x; }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;
// }}}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<mint> v(k + 1);
mint ans = 0;
for (int i = k; i > 0; i--) {
mint x = k / i;
v[i] = x.pow(n);
for (int j = 2 * i; j <= k; j += i) {
v[i] -= v[j];
}
ans += v[i] * i;
}
cout << ans << endl;
return 0;
} | replace | 107 | 108 | 107 | 108 | 0 | |
p02715 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
static inline DOUBLE ABS(DOUBLE a) { return 0 <= a ? a : -a; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 比較 */
bool operator==(const MODINT a) { return (this->m_x == a.m_x); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
static void printVector(vector<SQWORD> v) {
for (auto m : v) {
printf("%lld ", m);
}
printf("\n");
}
/*-----------------------------------------------------*/
int main(void) {
SQWORD sqN = inputSQWORD();
SQWORD sqK = inputSQWORD();
vector<MODINT> vmiPowTable(sqK);
vector<MODINT> vmiGcdTable(sqK);
for (auto it = vmiPowTable.begin(); it != vmiPowTable.end(); ++it) {
*it = MODINT(0);
}
MODINT miAns;
for (SQWORD sqGcd = sqK; 1 <= sqGcd; sqGcd--) {
SQWORD sqUnitNum = sqK / sqGcd;
MODINT miDivNum;
if (vmiPowTable[sqUnitNum] == MODINT(0)) {
MODINT tmp(sqUnitNum);
vmiPowTable[sqUnitNum] = tmp.pow(sqN);
}
miDivNum = vmiPowTable[sqUnitNum];
MODINT miGcdNum = miDivNum;
{
SQWORD sqMulCur = sqGcd * 2;
while (sqMulCur <= sqK) {
miGcdNum -= vmiGcdTable[sqMulCur];
sqMulCur += sqGcd;
}
}
vmiGcdTable[sqGcd] = miGcdNum;
// printf("%lld --- %lld\n", sqGcd, miGcdNum);
miAns += miGcdNum * MODINT(sqGcd);
}
printf("%lld\n", miAns);
return 0;
} | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
static inline DOUBLE ABS(DOUBLE a) { return 0 <= a ? a : -a; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 比較 */
bool operator==(const MODINT a) { return (this->m_x == a.m_x); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
static void printVector(vector<SQWORD> v) {
for (auto m : v) {
printf("%lld ", m);
}
printf("\n");
}
/*-----------------------------------------------------*/
int main(void) {
SQWORD sqN = inputSQWORD();
SQWORD sqK = inputSQWORD();
vector<MODINT> vmiPowTable(sqK + 1);
vector<MODINT> vmiGcdTable(sqK + 1);
for (auto it = vmiPowTable.begin(); it != vmiPowTable.end(); ++it) {
*it = MODINT(0);
}
MODINT miAns;
for (SQWORD sqGcd = sqK; 1 <= sqGcd; sqGcd--) {
SQWORD sqUnitNum = sqK / sqGcd;
MODINT miDivNum;
if (vmiPowTable[sqUnitNum] == MODINT(0)) {
MODINT tmp(sqUnitNum);
vmiPowTable[sqUnitNum] = tmp.pow(sqN);
}
miDivNum = vmiPowTable[sqUnitNum];
MODINT miGcdNum = miDivNum;
{
SQWORD sqMulCur = sqGcd * 2;
while (sqMulCur <= sqK) {
miGcdNum -= vmiGcdTable[sqMulCur];
sqMulCur += sqGcd;
}
}
vmiGcdTable[sqGcd] = miGcdNum;
// printf("%lld --- %lld\n", sqGcd, miGcdNum);
miAns += miGcdNum * MODINT(sqGcd);
}
printf("%lld\n", miAns);
return 0;
} | replace | 264 | 266 | 264 | 266 | 0 | |
p02715 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
const int MAX = 510000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i != 0)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
vector<int> c;
void f(const vector<pair<ll, int>> &v, int ind, int x) {
if (ind == v.size()) {
c[x]++;
return;
}
int b = 1;
rep(i, v[ind].second + 1) {
f(v, ind + 1, x * b);
b *= v[ind].first;
}
}
// 正剰余
long long mod(long long a, long long b) {
return a - (long long)std::floor((double)a / (double)b) * b;
}
int main() {
COMinit();
int N, K;
cin >> N >> K;
c.resize(K + 1);
rep(i, K + 1) c[i] = 0;
repi(i, 1, K + 1) { f(factorize(i), 0, 1); }
vector<ll> sum(K + 1);
rep(i, K + 1) sum[i] = 0;
for (int i = K; i >= 1; --i) {
sum[i] = 1;
rep(j, N) sum[i] = mod(sum[i] * c[i], MOD);
for (int j = 2; i * j <= K; ++j)
sum[i] = mod(sum[i] - sum[i * j], MOD);
}
ll res = 0;
rep(i, K + 1) {
res += sum[i] * i;
res %= MOD;
}
cout << res << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
#define repi(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
const int MAX = 510000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 素因数分解
vector<pair<long long, int>> factorize(long long n) {
vector<pair<long long, int>> res;
for (long long i = 2; i * i <= n; ++i) {
if (n % i != 0)
continue;
res.emplace_back(i, 0);
while (n % i == 0) {
n /= i;
res.back().second++;
}
}
if (n != 1)
res.emplace_back(n, 1);
return res;
}
vector<int> c;
void f(const vector<pair<ll, int>> &v, int ind, int x) {
if (ind == v.size()) {
c[x]++;
return;
}
int b = 1;
rep(i, v[ind].second + 1) {
f(v, ind + 1, x * b);
b *= v[ind].first;
}
}
// 正剰余
long long mod(long long a, long long b) {
return a - (long long)std::floor((double)a / (double)b) * b;
}
int main() {
COMinit();
int N, K;
cin >> N >> K;
c.resize(K + 1);
rep(i, K + 1) c[i] = 0;
repi(i, 1, K + 1) { f(factorize(i), 0, 1); }
vector<ll> sum(K + 1);
rep(i, K + 1) sum[i] = 0;
for (int i = K; i >= 1; --i) {
sum[i] = 1;
ll b = c[i];
for (int j = 0; (N >> j) > 0; j++) {
if (((N >> j) & 1) == 1)
sum[i] = (sum[i] * b) % MOD;
b = (b * b) % MOD;
}
for (int j = 2; i * j <= K; ++j)
sum[i] = mod(sum[i] - sum[i * j], MOD);
}
ll res = 0;
rep(i, K + 1) {
res += sum[i] * i;
res %= MOD;
}
cout << res << endl;
return 0;
}
| replace | 99 | 100 | 99 | 105 | TLE | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
template <class T> void chmin(T &x, T y) {
if (x > y)
x = y;
}
template <class T> void chmax(T &x, T y) {
if (x < y)
x = y;
}
template <long long mod> struct modint {
long long num;
constexpr modint(long long x = 0) : num((x + mod) % mod) {}
constexpr modint &operator+=(const modint &rhs) {
num = (num + rhs.num) % mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) {
num -= rhs.num;
while (num < 0)
num += mod;
num %= mod;
return *this;
}
constexpr modint &operator*=(const modint &rhs) {
num = num * rhs.num % mod;
return *this;
}
constexpr modint &operator/=(modint rhs) {
int exp = mod - 2;
while (exp > 0) {
if (exp % 2)
*this *= rhs;
rhs *= rhs;
exp /= 2;
}
return *this;
}
constexpr modint operator++() {
++num;
return *this;
}
constexpr modint operator++(int n) {
modint tmp = *this;
++(*this);
return tmp;
}
constexpr modint operator--() {
--num;
return *this;
}
constexpr modint operator--(int n) {
const modint tmp = *this;
--(*this);
return tmp;
}
constexpr modint operator+(const modint &rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const {
return modint(*this) /= rhs;
}
modint modpow(long long exp) {
modint res = 1;
while (exp > 0) {
if (exp % 2)
res *= (*this);
(*this) *= (*this);
exp /= 2;
}
(*this) = res;
}
friend ostream &operator<<(ostream &lhs, const modint &rhs) {
return lhs << rhs.num;
}
friend istream &operator>>(istream &lhs, modint &rhs) {
long long tmp;
lhs >> rhs.num;
return lhs;
}
};
#define mint modint<1000000007>
int N, K;
mint sum = 0;
mint cnt[100010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> K;
for (int i = 1; i <= K; i++) {
cnt[i] = K / i;
cnt[i].modpow(N);
}
for (int i = K; i >= 1; i--) {
for (int j = i + i; j <= K; j += i) {
cnt[i] -= cnt[j];
}
sum += cnt[i] * i;
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
template <class T> void chmin(T &x, T y) {
if (x > y)
x = y;
}
template <class T> void chmax(T &x, T y) {
if (x < y)
x = y;
}
template <long long mod> struct modint {
long long num;
constexpr modint(long long x = 0) : num((x + mod) % mod) {}
constexpr modint &operator+=(const modint &rhs) {
num = (num + rhs.num) % mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) {
num -= rhs.num;
while (num < 0)
num += mod;
num %= mod;
return *this;
}
constexpr modint &operator*=(const modint &rhs) {
num = num * rhs.num % mod;
return *this;
}
constexpr modint &operator/=(modint rhs) {
int exp = mod - 2;
while (exp > 0) {
if (exp % 2)
*this *= rhs;
rhs *= rhs;
exp /= 2;
}
return *this;
}
constexpr modint operator++() {
++num;
return *this;
}
constexpr modint operator++(int n) {
modint tmp = *this;
++(*this);
return tmp;
}
constexpr modint operator--() {
--num;
return *this;
}
constexpr modint operator--(int n) {
const modint tmp = *this;
--(*this);
return tmp;
}
constexpr modint operator+(const modint &rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const {
return modint(*this) /= rhs;
}
void modpow(long long exp) {
modint res = 1;
while (exp > 0) {
if (exp % 2)
res *= (*this);
(*this) *= (*this);
exp /= 2;
}
(*this) = res;
}
friend ostream &operator<<(ostream &lhs, const modint &rhs) {
return lhs << rhs.num;
}
friend istream &operator>>(istream &lhs, modint &rhs) {
long long tmp;
lhs >> rhs.num;
return lhs;
}
};
#define mint modint<1000000007>
int N, K;
mint sum = 0;
mint cnt[100010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> K;
for (int i = 1; i <= K; i++) {
cnt[i] = K / i;
cnt[i].modpow(N);
}
for (int i = K; i >= 1; i--) {
for (int j = i + i; j <= K; j += i) {
cnt[i] -= cnt[j];
}
sum += cnt[i] * i;
}
cout << sum << endl;
return 0;
} | replace | 85 | 86 | 85 | 86 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL modpow(LL x, LL n) {
LL r = 1;
while (n != 0) {
if (n & 1)
r = r * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return r;
}
int main() {
int N, K;
cin >> N >> K;
vector<LL> count(N + 1);
LL ret = 0;
for (int i = K; i >= 1; --i) {
LL n = modpow(K / i, N);
for (int j = i * 2; j <= K; j += i) {
n = (n + MOD - count[j]) % MOD;
}
count[i] = n;
ret = (ret + n * i) % MOD;
}
cout << ret << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL modpow(LL x, LL n) {
LL r = 1;
while (n != 0) {
if (n & 1)
r = r * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return r;
}
int main() {
int N, K;
cin >> N >> K;
vector<LL> count(K + 1);
LL ret = 0;
for (int i = K; i >= 1; --i) {
LL n = modpow(K / i, N);
for (int j = i * 2; j <= K; j += i) {
n = (n + MOD - count[j]) % MOD;
}
count[i] = n;
ret = (ret + n * i) % MOD;
}
cout << ret << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
static const int64_t MOD = 1000000007;
int64_t modpow(int64_t base, int64_t k, int64_t mod) {
base %= mod;
int64_t answer = 1;
while (k > 0) {
if (k & 1)
answer = (answer * base) % mod;
base = (base * base) % mod;
k >>= 1;
}
return answer;
}
int main() {
int64_t N, K;
cin >> N >> K;
vector<int64_t> counts(K);
int64_t answer = 0;
for (int64_t gcd = K; gcd >= 1; gcd--) {
int64_t multiples = K / gcd;
int64_t count = modpow(multiples, N, MOD);
for (int k = 2; gcd * k <= K; k++) {
count = (count + MOD - counts[gcd * k]) % MOD;
}
counts[gcd] = count;
answer = (answer + gcd * counts[gcd]) % MOD;
}
cout << answer << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
static const int64_t MOD = 1000000007;
int64_t modpow(int64_t base, int64_t k, int64_t mod) {
base %= mod;
int64_t answer = 1;
while (k > 0) {
if (k & 1)
answer = (answer * base) % mod;
base = (base * base) % mod;
k >>= 1;
}
return answer;
}
int main() {
int64_t N, K;
cin >> N >> K;
vector<int64_t> counts(K + 1);
int64_t answer = 0;
for (int64_t gcd = K; gcd >= 1; gcd--) {
int64_t multiples = K / gcd;
int64_t count = modpow(multiples, N, MOD);
for (int k = 2; gcd * k <= K; k++) {
count = (count + MOD - counts[gcd * k]) % MOD;
}
counts[gcd] = count;
answer = (answer + gcd * counts[gcd]) % MOD;
}
cout << answer << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02715 | C++ | Runtime Error | #line 1 "/mnt/c/Users/leafc/dev/compro/lib/math/modint.hpp"
#include <cstdint>
#include <iostream>
#ifndef MOD_INT
#define MOD_INT
template <std::uint_fast64_t MOD> class ModInt {
using u64 = std::uint_fast64_t;
public:
ModInt(const u64 val = 0) { value = val % MOD; }
ModInt operator+(const ModInt rhs) const { return ModInt(*this) += rhs; }
ModInt operator-(const ModInt rhs) const { return ModInt(*this) -= rhs; }
ModInt operator*(const ModInt rhs) const { return ModInt(*this) *= rhs; }
ModInt operator/(const ModInt rhs) const { return ModInt(*this) /= rhs; }
ModInt &operator+=(const ModInt rhs) {
value += rhs.value;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator-=(const ModInt rhs) {
if (value < rhs.value) {
value += MOD;
}
value -= rhs.value;
return *this;
}
ModInt &operator*=(const ModInt rhs) {
value = value * rhs.value % MOD;
return *this;
}
ModInt &operator/=(ModInt rhs) {
*this *= rhs.inv();
return *this;
}
ModInt &operator++(int n) {
value++;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator--(int n) {
if (value == 0) {
value += MOD;
}
value--;
return *this;
}
ModInt inv() { return ModInt::pow(*this, MOD - 2); }
static ModInt pow(ModInt base, long long int n) {
ModInt res = ModInt(1);
while (n) {
if (n & 1) {
res *= base;
}
base *= base;
n /= 2;
}
return res;
}
static ModInt comb(ModInt n, ModInt r) { return comb(n.value, r.value); }
static ModInt comb(int n, int r) {
if (n < r)
return ModInt(0);
ModInt res = ModInt(1);
for (int i = 0; i < r; i++) {
res *= ModInt(n - i);
}
ModInt inv = ModInt(1);
for (int i = 0; i < r; i++) {
inv *= ModInt(r - i);
}
return res / inv;
}
u64 getValue() const { return value; }
private:
u64 value;
friend std::ostream &operator<<(std::ostream &out, const ModInt<MOD> &m) {
out << m.value;
return out;
}
friend std::istream &operator>>(std::istream &in, ModInt &m) {
uint_fast64_t i;
in >> i;
m = ModInt(i);
return in;
}
};
#endif
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void say(bool val, T yes = "Yes", T no = "No") {
cout << (val ? yes : no) << endl;
}
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
#line 3 "abc162_e.cpp"
using mint = ModInt<1000000007>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<mint> memo(n + 1, mint(0));
for (int i = k; i >= 1; i--) {
memo[i] = mint::pow(mint(k / i), n);
for (int j = 2; j * i <= k; j++) {
memo[i] -= memo[j * i];
}
}
mint ans(0);
FOR(i, 1, k + 1) { ans += memo[i] * mint(i); }
cout << ans << endl;
return 0;
}
| #line 1 "/mnt/c/Users/leafc/dev/compro/lib/math/modint.hpp"
#include <cstdint>
#include <iostream>
#ifndef MOD_INT
#define MOD_INT
template <std::uint_fast64_t MOD> class ModInt {
using u64 = std::uint_fast64_t;
public:
ModInt(const u64 val = 0) { value = val % MOD; }
ModInt operator+(const ModInt rhs) const { return ModInt(*this) += rhs; }
ModInt operator-(const ModInt rhs) const { return ModInt(*this) -= rhs; }
ModInt operator*(const ModInt rhs) const { return ModInt(*this) *= rhs; }
ModInt operator/(const ModInt rhs) const { return ModInt(*this) /= rhs; }
ModInt &operator+=(const ModInt rhs) {
value += rhs.value;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator-=(const ModInt rhs) {
if (value < rhs.value) {
value += MOD;
}
value -= rhs.value;
return *this;
}
ModInt &operator*=(const ModInt rhs) {
value = value * rhs.value % MOD;
return *this;
}
ModInt &operator/=(ModInt rhs) {
*this *= rhs.inv();
return *this;
}
ModInt &operator++(int n) {
value++;
if (value >= MOD) {
value -= MOD;
}
return *this;
}
ModInt &operator--(int n) {
if (value == 0) {
value += MOD;
}
value--;
return *this;
}
ModInt inv() { return ModInt::pow(*this, MOD - 2); }
static ModInt pow(ModInt base, long long int n) {
ModInt res = ModInt(1);
while (n) {
if (n & 1) {
res *= base;
}
base *= base;
n /= 2;
}
return res;
}
static ModInt comb(ModInt n, ModInt r) { return comb(n.value, r.value); }
static ModInt comb(int n, int r) {
if (n < r)
return ModInt(0);
ModInt res = ModInt(1);
for (int i = 0; i < r; i++) {
res *= ModInt(n - i);
}
ModInt inv = ModInt(1);
for (int i = 0; i < r; i++) {
inv *= ModInt(r - i);
}
return res / inv;
}
u64 getValue() const { return value; }
private:
u64 value;
friend std::ostream &operator<<(std::ostream &out, const ModInt<MOD> &m) {
out << m.value;
return out;
}
friend std::istream &operator>>(std::istream &in, ModInt &m) {
uint_fast64_t i;
in >> i;
m = ModInt(i);
return in;
}
};
#endif
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<
using namespace std;
template <class T> void say(bool val, T yes = "Yes", T no = "No") {
cout << (val ? yes : no) << endl;
}
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
#line 3 "abc162_e.cpp"
using mint = ModInt<1000000007>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<mint> memo(k + 1, mint(0));
for (int i = k; i >= 1; i--) {
memo[i] = mint::pow(mint(k / i), n);
for (int j = 2; j * i <= k; j++) {
memo[i] -= memo[j * i];
}
}
mint ans(0);
FOR(i, 1, k + 1) { ans += memo[i] * mint(i); }
cout << ans << endl;
return 0;
}
| replace | 147 | 148 | 147 | 148 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long BIG = 1000000007;
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
long N, K;
long long ans = 0;
cin >> N >> K;
vector<long> vec(N + 10, -1);
for (int i = K; i > 0; i--) {
vec[i] = modpow(K / i, N, BIG);
for (int j = i * 2; j <= K; j += i) {
vec[i] = (vec[i] - vec[j] + BIG) % BIG;
}
ans = (ans % BIG + vec[i] * i % BIG) % BIG;
// cout << ans << endl;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long BIG = 1000000007;
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
long N, K;
long long ans = 0;
cin >> N >> K;
vector<long> vec(K + 10, -1);
for (int i = K; i > 0; i--) {
vec[i] = modpow(K / i, N, BIG);
for (int j = i * 2; j <= K; j += i) {
vec[i] = (vec[i] - vec[j] + BIG) % BIG;
}
ans = (ans % BIG + vec[i] * i % BIG) % BIG;
// cout << ans << endl;
}
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
/*
#include<boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
*/
using namespace std;
#define ll long long int
#define lo mp::cpp_int
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl "\n"
#define ce(x) cout << x << "\n"
#define fill(s, v) memset(s, v, sizeof(s))
#define speed \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
}
#define deb(x) cout << #x << " " << x << endl;
#define INFINITE 1000000009
#define ull unsigned long long int
#define take(a, n) \
for (ll pp = 0; pp < n; pp++) { \
cin >> a[pp]; \
}
#define take2(a, n) \
for (ll p = 0; p < n; p++) { \
yo temp; \
cin >> temp; \
a.pb(temp); \
}
#define f(i, n) for (ll i = 0; i < n; i++)
#define f1(i, a, n) for (ll i = a; i < n; i++)
#define show(a, n) \
for (ll p = 0; p < n; p++) \
cout << a[p] << " ";
#define _ << " " <<
#define nl cout << endl;
#define sq(x) ((x) * (x))
#define call(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define lld long double
#define sc(n) scanf("%lld", &n);
#define de2(x, y) \
cout << #x << " = " << (x) << ' ' << #y << " = " << y << endl; \
typedef pair<int, int> pii;
#define copy(b, a, n) \
for (ll i = 0; i < n; i++) \
b[i] = a[i];
#define tc(tt) \
ll tt; \
cin >> tt; \
for (int _tt = 0; _tt < tt; _tt++)
typedef vector<vector<ll>> matrix;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
const ll dx[4] = {-1, 0, 1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll mod = 1000000007;
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
// ll power_mod(ll x,ll y,ll p){ll
// res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll modexpo(ll x, ll n, ll M) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modexpo((x * x) % M, n / 2, M);
else
return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll sumofdigits(ll n) {
ll out = 0;
while (n) {
out += (n % 10);
n /= 10;
}
return out;
}
bool isPrime(ll n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// ll power(ll a,ll b){if(b==0)return 1;if(b&1)return a*power(a,b-1);ll
// res=power(a,b/2);return res*res;}
ll bexpo(ll x, ll n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return bexpo(x * x, n / 2);
else
return x * bexpo(x * x, (n - 1) / 2);
}
ll log(ll d) { return log2(d); }
bool isPower(ll x, ll y) {
if (x == 1)
return (y == 1);
ll pow = 1;
while (pow < y)
pow *= x;
return (pow == y);
}
bool isPerfectSquare(long double x) {
long double sr = sqrt(x);
return ((sr - floor(sr)) == 0);
}
bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second < b.second);
}
ll isPalindrome(string s) {
ll l = 0;
ll h = s.size() - 1;
while (h > l) {
if (s[l++] != s[h--])
return 0;
}
return 1;
}
ll setbits(ll n) {
if (n == 0)
return 0;
else
return 1 + setbits(n & (n - 1));
}
ll modInverse(ll A, ll M) { return modexpo(A, M - 2, M); }
//------modular inverse by extended euclid-------//
// ll d, x, y;
// void extendedEuclid(ll A, ll B) {
// if(B == 0) {
// d = A;
// x = 1;
// y = 0;
// }
// else {
// extendedEuclid(B, A%B);
// ll temp = x;
// x = y;
// y = temp - (A/B)*y;
// }
// }
// ll modInverse2(ll A, ll M){
// extendedEuclid(A,M);
// return (x%M+M)%M;
// }
//---------------------------------//
//---------------matrix exponentiation-------------------//
// matrix mul(matrix a,matrix b){
// matrix res(n+1,vector<ll>(n+1));
// f(i,n)f(j,n)f(k,n)res[i][j]=(res[i][j]%mod+((a[i][k]%mod)*(b[k][j]%mod))%mod)%mod;
// return res;
// }
// matrix pow(matrix A,ll p) {
// if(p==1) return A;
// matrix res=pow(A,p/2) ;
// res=mul(res,res);
// if(p&1) res=mul(res,A) ;
// return res;
// }
//-------------------------------------------------//
vector<ll> factorize(ll n) {
vector<ll> res;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
vector<ll> divisors(ll n) {
vector<ll> res;
for (ll i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i) {
res.pb(i);
} else {
res.pb(n / i);
res.pb(i);
}
}
}
return res;
}
vector<ll> primeFactors(ll n) {
if (n == 1)
return vector<ll>(1, 1);
bool idx[1] = {false};
vector<ll> res;
while (n % 2 == 0) {
if (!idx[1]) {
idx[1] = true;
res.pb(2);
}
n = n / 2;
}
for (ll i = 3; i * i <= n; i += 2) {
bool once = false;
while (n % i == 0) {
if (!once) {
res.pb(i);
once = true;
}
n = n / i;
}
}
if (n > 2)
res.pb(n);
return res;
}
ll phi(ll n) {
float result = n;
for (ll p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result *= (1.0 - (1.0 / (float)p));
}
}
if (n > 1)
result *= (1.0 - (1.0 / (float)n));
return (ll)result % mod;
}
ll phi2(ll n) {
ll m = n;
double ans = n;
for (ll i = 2; i * i <= n; i++) {
ll count = 0;
while (n > 1 && n % i == 0) {
n = n / i;
count++;
}
if (count > 0) {
ans = ans * (1.0 - (1.0 / i));
}
}
if (n > 1) {
ans = ans * (1.0 - (1.0 / n));
}
ll ans2 = ans;
return ans2 % mod;
}
//-------------dfs------------------//
// ll n;
// 100005
// vector<ll> ed[100005];
// vector<ll> vec[100005];
// bool check[100005];
// ll com[100005];
// ll nodes;
// void dfs(ll n){
// nodes++;
// check[n]=true;
// for(ll i=0;i<ed[n].size();i++){
// if(!check[ed[n][i]]){
// dfs(ed[n][i]);
// }
// }
// }
//--------------------------------------------//
ll djikshtra(ll n, vector<pii> graph[], ll src, ll dst) {
vector<ll> dist(n + 1, LONG_MAX);
priority_queue<pii, vector<pii>, greater<pii>> heap;
vector<bool> visited(n + 1, false);
dist[src] = 0;
heap.push({dist[src], src});
while (!heap.empty()) {
pii curr = heap.top();
heap.pop();
if (visited[curr.second])
continue;
visited[curr.second] = true;
for (auto it : graph[curr.second]) {
if (visited[it.first])
continue;
if (dist[it.first] > dist[curr.second] + it.second) {
dist[it.first] = dist[curr.second] + it.second;
heap.push({dist[it.first], it.first});
}
}
if (curr.second == dst)
break;
}
return dist[dst];
}
ll dxx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dyy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//----check if a point is in range-----///
// bool check(ll x,ll y){return(x>=0&&x<n&&y>=0&&y<m);}
//--------------------------------------------////
//---sieve of eranthoses------//
// #define size 1000001
// char prim[1000001];
// ll sum[1000001];
// void gen()
// {
// for(ll i=2; i*i<size;++i)
// {
// if(prim[i]==0) // i is a prime number
// {
// for(ll j=i<<1;j<size; j+=i)
// prim[j] = 1; // j is not a prime number
// }
// }
// sum[0] = sum[1] = 0;
// for(ll i = 2; i < size; ++i)
// {
// sum[i] = prim[i] == 0;
// if(i)
// sum[i] += sum[i - 1];
// }
// }
//------------------------//
const int FULL_MASK = (1 << 10) - 1;
void solve() {
ll n, k;
cin >> n >> k;
std::vector<ll> dp(n + 1, 0);
for (ll gd = k; gd > 0; gd--) {
ll temp = k / gd;
temp = modexpo(temp, n, mod);
ll ex = 0;
for (ll j = (2 * gd); j <= k; j += gd) {
ex = (ex + dp[j]) % mod;
}
dp[gd] = (temp - ex + mod) % mod;
}
ll ans = 0;
for (ll i = 1; i <= k; i++) {
ans = (ans + (dp[i] * i) % mod) % mod;
}
ce(ans % mod);
}
int main() {
// speed
// tc(tt){
solve();
// }
}
/*
7
RGRBGRB
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
*/ // cout<<"1st dif->"<<endl;
// for(auto it:dif1){
// cout<<it.ff<<" "<<it.ss<<endl;
// }
// cout<<"2nd dif->"<<endl;
// for(auto it:dif2){
// cout<<it.ff<<" "<<it.ss<<endl;
// }
// nl | #include <bits/stdc++.h>
/*
#include<boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;
*/
using namespace std;
#define ll long long int
#define lo mp::cpp_int
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl "\n"
#define ce(x) cout << x << "\n"
#define fill(s, v) memset(s, v, sizeof(s))
#define speed \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
}
#define deb(x) cout << #x << " " << x << endl;
#define INFINITE 1000000009
#define ull unsigned long long int
#define take(a, n) \
for (ll pp = 0; pp < n; pp++) { \
cin >> a[pp]; \
}
#define take2(a, n) \
for (ll p = 0; p < n; p++) { \
yo temp; \
cin >> temp; \
a.pb(temp); \
}
#define f(i, n) for (ll i = 0; i < n; i++)
#define f1(i, a, n) for (ll i = a; i < n; i++)
#define show(a, n) \
for (ll p = 0; p < n; p++) \
cout << a[p] << " ";
#define _ << " " <<
#define nl cout << endl;
#define sq(x) ((x) * (x))
#define call(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ff first
#define ss second
#define lld long double
#define sc(n) scanf("%lld", &n);
#define de2(x, y) \
cout << #x << " = " << (x) << ' ' << #y << " = " << y << endl; \
typedef pair<int, int> pii;
#define copy(b, a, n) \
for (ll i = 0; i < n; i++) \
b[i] = a[i];
#define tc(tt) \
ll tt; \
cin >> tt; \
for (int _tt = 0; _tt < tt; _tt++)
typedef vector<vector<ll>> matrix;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
const ll dx[4] = {-1, 0, 1, 0};
const ll dy[4] = {0, -1, 0, 1};
const ll mod = 1000000007;
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
// ll power_mod(ll x,ll y,ll p){ll
// res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll modexpo(ll x, ll n, ll M) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modexpo((x * x) % M, n / 2, M);
else
return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll sumofdigits(ll n) {
ll out = 0;
while (n) {
out += (n % 10);
n /= 10;
}
return out;
}
bool isPrime(ll n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// ll power(ll a,ll b){if(b==0)return 1;if(b&1)return a*power(a,b-1);ll
// res=power(a,b/2);return res*res;}
ll bexpo(ll x, ll n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return bexpo(x * x, n / 2);
else
return x * bexpo(x * x, (n - 1) / 2);
}
ll log(ll d) { return log2(d); }
bool isPower(ll x, ll y) {
if (x == 1)
return (y == 1);
ll pow = 1;
while (pow < y)
pow *= x;
return (pow == y);
}
bool isPerfectSquare(long double x) {
long double sr = sqrt(x);
return ((sr - floor(sr)) == 0);
}
bool compare(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second < b.second);
}
ll isPalindrome(string s) {
ll l = 0;
ll h = s.size() - 1;
while (h > l) {
if (s[l++] != s[h--])
return 0;
}
return 1;
}
ll setbits(ll n) {
if (n == 0)
return 0;
else
return 1 + setbits(n & (n - 1));
}
ll modInverse(ll A, ll M) { return modexpo(A, M - 2, M); }
//------modular inverse by extended euclid-------//
// ll d, x, y;
// void extendedEuclid(ll A, ll B) {
// if(B == 0) {
// d = A;
// x = 1;
// y = 0;
// }
// else {
// extendedEuclid(B, A%B);
// ll temp = x;
// x = y;
// y = temp - (A/B)*y;
// }
// }
// ll modInverse2(ll A, ll M){
// extendedEuclid(A,M);
// return (x%M+M)%M;
// }
//---------------------------------//
//---------------matrix exponentiation-------------------//
// matrix mul(matrix a,matrix b){
// matrix res(n+1,vector<ll>(n+1));
// f(i,n)f(j,n)f(k,n)res[i][j]=(res[i][j]%mod+((a[i][k]%mod)*(b[k][j]%mod))%mod)%mod;
// return res;
// }
// matrix pow(matrix A,ll p) {
// if(p==1) return A;
// matrix res=pow(A,p/2) ;
// res=mul(res,res);
// if(p&1) res=mul(res,A) ;
// return res;
// }
//-------------------------------------------------//
vector<ll> factorize(ll n) {
vector<ll> res;
for (ll i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res.push_back(i);
n /= i;
}
}
if (n != 1) {
res.push_back(n);
}
return res;
}
vector<ll> divisors(ll n) {
vector<ll> res;
for (ll i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i) {
res.pb(i);
} else {
res.pb(n / i);
res.pb(i);
}
}
}
return res;
}
vector<ll> primeFactors(ll n) {
if (n == 1)
return vector<ll>(1, 1);
bool idx[1] = {false};
vector<ll> res;
while (n % 2 == 0) {
if (!idx[1]) {
idx[1] = true;
res.pb(2);
}
n = n / 2;
}
for (ll i = 3; i * i <= n; i += 2) {
bool once = false;
while (n % i == 0) {
if (!once) {
res.pb(i);
once = true;
}
n = n / i;
}
}
if (n > 2)
res.pb(n);
return res;
}
ll phi(ll n) {
float result = n;
for (ll p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0)
n /= p;
result *= (1.0 - (1.0 / (float)p));
}
}
if (n > 1)
result *= (1.0 - (1.0 / (float)n));
return (ll)result % mod;
}
ll phi2(ll n) {
ll m = n;
double ans = n;
for (ll i = 2; i * i <= n; i++) {
ll count = 0;
while (n > 1 && n % i == 0) {
n = n / i;
count++;
}
if (count > 0) {
ans = ans * (1.0 - (1.0 / i));
}
}
if (n > 1) {
ans = ans * (1.0 - (1.0 / n));
}
ll ans2 = ans;
return ans2 % mod;
}
//-------------dfs------------------//
// ll n;
// 100005
// vector<ll> ed[100005];
// vector<ll> vec[100005];
// bool check[100005];
// ll com[100005];
// ll nodes;
// void dfs(ll n){
// nodes++;
// check[n]=true;
// for(ll i=0;i<ed[n].size();i++){
// if(!check[ed[n][i]]){
// dfs(ed[n][i]);
// }
// }
// }
//--------------------------------------------//
ll djikshtra(ll n, vector<pii> graph[], ll src, ll dst) {
vector<ll> dist(n + 1, LONG_MAX);
priority_queue<pii, vector<pii>, greater<pii>> heap;
vector<bool> visited(n + 1, false);
dist[src] = 0;
heap.push({dist[src], src});
while (!heap.empty()) {
pii curr = heap.top();
heap.pop();
if (visited[curr.second])
continue;
visited[curr.second] = true;
for (auto it : graph[curr.second]) {
if (visited[it.first])
continue;
if (dist[it.first] > dist[curr.second] + it.second) {
dist[it.first] = dist[curr.second] + it.second;
heap.push({dist[it.first], it.first});
}
}
if (curr.second == dst)
break;
}
return dist[dst];
}
ll dxx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dyy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//----check if a point is in range-----///
// bool check(ll x,ll y){return(x>=0&&x<n&&y>=0&&y<m);}
//--------------------------------------------////
//---sieve of eranthoses------//
// #define size 1000001
// char prim[1000001];
// ll sum[1000001];
// void gen()
// {
// for(ll i=2; i*i<size;++i)
// {
// if(prim[i]==0) // i is a prime number
// {
// for(ll j=i<<1;j<size; j+=i)
// prim[j] = 1; // j is not a prime number
// }
// }
// sum[0] = sum[1] = 0;
// for(ll i = 2; i < size; ++i)
// {
// sum[i] = prim[i] == 0;
// if(i)
// sum[i] += sum[i - 1];
// }
// }
//------------------------//
const int FULL_MASK = (1 << 10) - 1;
void solve() {
ll n, k;
cin >> n >> k;
std::vector<ll> dp(k + 1, 0);
for (ll gd = k; gd > 0; gd--) {
ll temp = k / gd;
temp = modexpo(temp, n, mod);
ll ex = 0;
for (ll j = (2 * gd); j <= k; j += gd) {
ex = (ex + dp[j]) % mod;
}
dp[gd] = (temp - ex + mod) % mod;
}
ll ans = 0;
for (ll i = 1; i <= k; i++) {
ans = (ans + (dp[i] * i) % mod) % mod;
}
ce(ans % mod);
}
int main() {
// speed
// tc(tt){
solve();
// }
}
/*
7
RGRBGRB
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
*/ // cout<<"1st dif->"<<endl;
// for(auto it:dif1){
// cout<<it.ff<<" "<<it.ss<<endl;
// }
// cout<<"2nd dif->"<<endl;
// for(auto it:dif2){
// cout<<it.ff<<" "<<it.ss<<endl;
// }
// nl | replace | 359 | 360 | 359 | 360 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double, double> PD;
typedef pair<int, P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
typedef vector<mint> vm;
typedef vector<vm> vvm;
int main() {
int N, K;
cin >> N >> K;
mint ans = 0;
vm dp(K, 0);
drep(x, K + 1) {
if (!x)
break;
mint res = K / x;
res = res.pow(N);
dp[x] = res;
for (int k = 2 * x; k <= K; k += x) {
dp[x] -= dp[k];
}
ans += dp[x] * x;
}
cout << ans.x << endl;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double, double> PD;
typedef pair<int, P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
struct mint {
ll x;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
typedef vector<mint> vm;
typedef vector<vm> vvm;
int main() {
int N, K;
cin >> N >> K;
mint ans = 0;
vm dp(K + 1, 0);
drep(x, K + 1) {
if (!x)
break;
mint res = K / x;
res = res.pow(N);
dp[x] = res;
for (int k = 2 * x; k <= K; k += x) {
dp[x] -= dp[k];
}
ans += dp[x] * x;
}
cout << ans.x << endl;
return 0;
} | replace | 76 | 77 | 76 | 77 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLL(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
//* Mod int
const int mod = 1000000007;
struct mint {
ll x;
mint() : x(0) {}
mint(ll x) : x((x % mod + mod) % mod) {}
// mint(ll x):x(x){}
mint &fix() {
x = (x % mod + mod) % mod;
return *this;
}
mint operator-() const { return mint(0) - *this; }
mint &operator+=(const mint &a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint &a) const { return mint(*this) += a; }
mint operator-(const mint &a) const { return mint(*this) -= a; }
mint operator*(const mint &a) const { return mint(*this) *= a; }
bool operator<(const mint &a) const { return x < a.x; }
bool operator==(const mint &a) const { return x == a.x; }
};
istream &operator>>(istream &i, mint &a) {
i >> a.x;
return i;
}
ostream &operator<<(ostream &o, const mint &a) {
o << a.x;
return o;
}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//*/
long long modPow(long long x, long long n) {
if (n == 0)
return 1;
if (n % 2 == 0) {
long long sqrtX = modPow(x, n / 2);
return sqrtX * sqrtX % mod;
} else {
return x * modPow(x, n - 1) % mod;
}
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX]; // mod MOD k の逆元 inv[k]
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 順列計算
long long perm(long long a, long long b) {
if (a < b)
return 0;
long long tmp = finv[a - b] % MOD;
return tmp * fac[a] % MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
VLL sum(n + 1, 0);
vm gcdCnt(n + 1, 0);
mint ans = 0;
FOR(i, 1, k + 1) { sum[i] = k / i; }
for (int i = k; i >= 1; i--) {
gcdCnt[i] = modPow(sum[i], n);
ll x = 2;
while (i * x <= k) {
gcdCnt[i] -= gcdCnt[i * x];
x++;
}
ans += (mint)i * gcdCnt[i];
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLL(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
//* Mod int
const int mod = 1000000007;
struct mint {
ll x;
mint() : x(0) {}
mint(ll x) : x((x % mod + mod) % mod) {}
// mint(ll x):x(x){}
mint &fix() {
x = (x % mod + mod) % mod;
return *this;
}
mint operator-() const { return mint(0) - *this; }
mint &operator+=(const mint &a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint &a) const { return mint(*this) += a; }
mint operator-(const mint &a) const { return mint(*this) -= a; }
mint operator*(const mint &a) const { return mint(*this) *= a; }
bool operator<(const mint &a) const { return x < a.x; }
bool operator==(const mint &a) const { return x == a.x; }
};
istream &operator>>(istream &i, mint &a) {
i >> a.x;
return i;
}
ostream &operator<<(ostream &o, const mint &a) {
o << a.x;
return o;
}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//*/
long long modPow(long long x, long long n) {
if (n == 0)
return 1;
if (n % 2 == 0) {
long long sqrtX = modPow(x, n / 2);
return sqrtX * sqrtX % mod;
} else {
return x * modPow(x, n - 1) % mod;
}
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX]; // mod MOD k の逆元 inv[k]
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 順列計算
long long perm(long long a, long long b) {
if (a < b)
return 0;
long long tmp = finv[a - b] % MOD;
return tmp * fac[a] % MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
VLL sum(k + 1, 0);
vm gcdCnt(k + 1, 0);
mint ans = 0;
FOR(i, 1, k + 1) { sum[i] = k / i; }
for (int i = k; i >= 1; i--) {
gcdCnt[i] = modPow(sum[i], n);
ll x = 2;
while (i * x <= k) {
gcdCnt[i] -= gcdCnt[i * x];
x++;
}
ans += (mint)i * gcdCnt[i];
}
cout << ans << endl;
return 0;
}
| replace | 150 | 152 | 150 | 152 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int, int>
#define PSI pair<string, int>
#define PIS pair<int, string>
#define PLI pair<long long int, int>
#define PLL pair<long long int, long long int>
#define MII map<int, int>
#define MSI map<string, int>
#define MIS map<int, string>
#define MLI map<long long int, int>
#define FAST() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
// int dx[]={-1,1,0,0};
// int dy[]={0,0,-1,1};
// int dx[]= {-1,0,1,-1,1,-1,0,1};
// int dy[]= {1,1,1,0,0,-1,-1,-1};
LL big_mod(LL val, LL pow, LL mod) {
LL res = 1;
val = val % mod;
while (pow > 0) {
if (pow & 1) {
res = (res * val) % mod;
}
pow = pow >> 1;
val = (val * val) % mod;
}
return res;
}
int main() {
FAST();
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
LL i, j, k, n, ans = 0;
const LL mod = 1e9 + 7;
cin >> n >> k;
LL cnt[k + 5];
for (i = 1; i <= n; i++)
cnt[i] = big_mod(k / i, n, mod);
for (i = k; i > 0; i--) {
for (j = i + i; j <= k; j += i)
cnt[i] = (cnt[i] - cnt[j] + mod) % mod;
}
for (i = 1; i <= k; i++)
ans = (ans + (cnt[i] * i) % mod) % mod;
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int, int>
#define PSI pair<string, int>
#define PIS pair<int, string>
#define PLI pair<long long int, int>
#define PLL pair<long long int, long long int>
#define MII map<int, int>
#define MSI map<string, int>
#define MIS map<int, string>
#define MLI map<long long int, int>
#define FAST() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
// int dx[]={-1,1,0,0};
// int dy[]={0,0,-1,1};
// int dx[]= {-1,0,1,-1,1,-1,0,1};
// int dy[]= {1,1,1,0,0,-1,-1,-1};
LL big_mod(LL val, LL pow, LL mod) {
LL res = 1;
val = val % mod;
while (pow > 0) {
if (pow & 1) {
res = (res * val) % mod;
}
pow = pow >> 1;
val = (val * val) % mod;
}
return res;
}
int main() {
FAST();
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
LL i, j, k, n, ans = 0;
const LL mod = 1e9 + 7;
cin >> n >> k;
LL cnt[k + 5];
for (i = 1; i <= k; i++)
cnt[i] = big_mod(k / i, n, mod);
for (i = k; i > 0; i--) {
for (j = i + i; j <= k; j += i)
cnt[i] = (cnt[i] - cnt[j] + mod) % mod;
}
for (i = 1; i <= k; i++)
ans = (ans + (cnt[i] * i) % mod) % mod;
cout << ans;
return 0;
}
| replace | 73 | 74 | 73 | 74 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
#define showm(m) \
{ \
for (auto i : m) { \
cout << i.x << " "; \
} \
cout << endl; \
}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }
long mod = 1000000007;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {} // コンストラクタ
/* 演算子オーバーロード */
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
} mint_t;
ll intpow(mint_t m, int n) {
if (n == 0)
return 1;
mint_t ans(1);
while (n >= 1) {
if ((n % 2) == 0) {
m *= m.x;
n /= 2;
} else {
ans *= m.x;
n -= 1;
}
}
return ans.x;
}
template <class X> void factorization(X input, vector<X> &Pnumber) {
for (X i = 2; i * i <= input; i++) {
if (input % i == 0) {
while (input % i == 0) {
input /= i;
Pnumber.push_back(i);
}
}
}
if (input != 1)
Pnumber.push_back(input);
}
/*
1~K以下の整数からなる長さNの数列
この数列は、K^Nのパターンが存在する。
この数列のK^Nの最大公約数の和
最大公約数がXとなるときのパターン数をf(X)とする。
f(K) = 1 (全てK)
f(K/2) = 2^N - f(K)
pをmの公倍数かつK以下の数とする。
f(m): (pの数)^N - f(p)の総和
*/
int main() {
int n, k;
cin >> n >> k;
vector<mint> f(k, 0);
for (int m = k; m >= 1; m--) {
// f(m)を包除原理で求める。
int pnum = k / m;
mint tans = pnum;
tans = tans.pow(n);
for (int i = 2; i <= pnum; i++) {
tans -= f[m * i];
}
f[m] = tans;
}
mint ans(0);
for (int i = 1; i <= k; i++) {
// cout << f[i].x << endl;
mint tans = f[i];
tans *= i;
ans += tans;
}
cout << ans.x << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
#define showm(m) \
{ \
for (auto i : m) { \
cout << i.x << " "; \
} \
cout << endl; \
}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }
long mod = 1000000007;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {} // コンストラクタ
/* 演算子オーバーロード */
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
} mint_t;
ll intpow(mint_t m, int n) {
if (n == 0)
return 1;
mint_t ans(1);
while (n >= 1) {
if ((n % 2) == 0) {
m *= m.x;
n /= 2;
} else {
ans *= m.x;
n -= 1;
}
}
return ans.x;
}
template <class X> void factorization(X input, vector<X> &Pnumber) {
for (X i = 2; i * i <= input; i++) {
if (input % i == 0) {
while (input % i == 0) {
input /= i;
Pnumber.push_back(i);
}
}
}
if (input != 1)
Pnumber.push_back(input);
}
/*
1~K以下の整数からなる長さNの数列
この数列は、K^Nのパターンが存在する。
この数列のK^Nの最大公約数の和
最大公約数がXとなるときのパターン数をf(X)とする。
f(K) = 1 (全てK)
f(K/2) = 2^N - f(K)
pをmの公倍数かつK以下の数とする。
f(m): (pの数)^N - f(p)の総和
*/
int main() {
int n, k;
cin >> n >> k;
vector<mint> f(k + 1, 0);
for (int m = k; m >= 1; m--) {
// f(m)を包除原理で求める。
int pnum = k / m;
mint tans = pnum;
tans = tans.pow(n);
for (int i = 2; i <= pnum; i++) {
tans -= f[m * i];
}
f[m] = tans;
}
mint ans(0);
for (int i = 1; i <= k; i++) {
// cout << f[i].x << endl;
mint tans = f[i];
tans *= i;
ans += tans;
}
cout << ans.x << endl;
}
| replace | 121 | 122 | 121 | 122 | 0 | |
p02715 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
long long power(long long a, long long b) {
long long ans = 1;
while (b) {
if (b % 2) {
ans = ans * a % mod;
}
a = a * a % mod;
b /= 2;
}
return ans;
}
int main() {
long long n, k;
cin >> n >> k;
vector<long long> a(k + 1, 0);
for (long long i = k; i >= 1; i--) {
a[i] = power(k / i, n);
int j = 2;
while (j <= i) {
a[i] = (a[i] - a[i * j]) % mod;
if (a[i] < 0) {
a[i] += mod;
}
j++;
}
}
long long ans = 0;
for (long long i = 1; i <= k; i++) {
ans += a[i] * i % mod;
ans %= mod;
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
long long power(long long a, long long b) {
long long ans = 1;
while (b) {
if (b % 2) {
ans = ans * a % mod;
}
a = a * a % mod;
b /= 2;
}
return ans;
}
int main() {
long long n, k;
cin >> n >> k;
vector<long long> a(k + 1, 0);
for (long long i = k; i >= 1; i--) {
a[i] = power(k / i, n);
int j = 2;
while (i * j <= k) {
a[i] = (a[i] - a[i * j]) % mod;
if (a[i] < 0) {
a[i] += mod;
}
j++;
}
}
long long ans = 0;
for (long long i = 1; i <= k; i++) {
ans += a[i] * i % mod;
ans %= mod;
}
cout << ans;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.