結果
| 問題 |
No.719 Coprime
|
| コンテスト | |
| ユーザー |
heno239
|
| 提出日時 | 2018-07-27 23:10:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,676 bytes |
| コンパイル時間 | 1,059 ms |
| コンパイル使用メモリ | 107,532 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-05 04:45:57 |
| 合計ジャッジ時間 | 6,463 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 43 TLE * 1 -- * 17 |
ソースコード
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int isp[1300]; vector<int> used; int h;
int gcd(int x,int y) {
if (x < y)swap(x, y);
while (y) {
int r = x % y; x = y; y = r;
}
return x;
}
int ma = 0;
void sum(int k,int s) {
if (k == 1)return;
if (k >= h && isp[k]) {
sum(k - 1,s); return;
}
int len = used.size();
bool f = true;
rep(i, len) {
if (gcd(used[i], k) > 1) {
f = false;
}
}
if (!f) {
sum(k - 1,s); return;
}
else {
sum(k - 1, s);
used.push_back(k);
sum(k - 1, s + k);
ma = max(ma, s + k);
used.pop_back();
return;
}
}
int main() {
fill(isp, isp + 1300, 1);
Rep(i, 2, 1300) {
if (isp[i]) {
for (int j = i * 2; j < 1300; j += i) {
isp[j] = 0;
}
}
}
int n; cin >> n; h = n/2 + 1;
int out = 0;
for (int i = n; i >= h; i--) {
if (isp[i])out += i;
}
sum(n, 0);
cout << out + ma << endl;
return 0;
}
heno239