Submission #1831819
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
//* 便利な変数
namespace {
int dx4[] = { 1, -1, 0, 0 };
int dy4[] = { 0, 0, 1, -1 };
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };
int mDays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
ll A, B, C, D, E, F, G, H, I, J, K, L, M,
N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
}
template <typename T>
vector<T> INP(ll n)
{
vector<T> x;
REP(i, n) {
T tmp; cin >> tmp;
x.push_back(tmp);
}
return move(x);
}
//* n文字1行の文字列を入力,一文字ごとの配列を返す
vector<char> SPRIT_STRING(ll n)
{
string str; cin >> str;
vector<char> cs(n);
REP(i, n) cs[i] = str[i];
return move(cs);
}
//* 文字列中から文字列を検索して別の文字列に置換する
void strReplace(std::string& str, const std::string& from, const std::string& to) {
std::string::size_type pos = 0;
while (pos = str.find(from, pos), pos != std::string::npos) {
str.replace(pos, from.length(), to);
pos += to.length();
}
}
//* 素数判定 is_prime<unsigned>(N)
template<typename T, std::enable_if_t<std::is_unsigned<T>::value, std::nullptr_t> = nullptr>
bool is_prime(const T n) {
if (n < 4) return n == 2 || n == 3;
if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
for (T i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
//* 組み合わせ計算
inline unsigned long long NChooseK(const unsigned long long& n,
const unsigned long long& k)
{
if (n < k) return 0;
if (0 == n) return 0;
if (0 == k) return 1;
if (n == k) return 1;
if (1 == k) return n;
typedef unsigned long long value_type;
value_type* table = new value_type[static_cast<std::size_t>(n * n)];
std::fill_n(table, n * n, 0);
class n_choose_k_impl
{
public:
n_choose_k_impl(value_type* table, const value_type& dimension)
: table_(table),
dimension_(dimension)
{}
inline value_type& lookup(const value_type& n, const value_type& k)
{
return table_[dimension_ * n + k];
}
inline value_type compute(const value_type& n, const value_type& k)
{
if ((0 == k) || (k == n))
return 1;
value_type v1 = lookup(n - 1, k - 1);
if (0 == v1)
v1 = lookup(n - 1, k - 1) = compute(n - 1, k - 1);
value_type v2 = lookup(n - 1, k);
if (0 == v2)
v2 = lookup(n - 1, k) = compute(n - 1, k);
return v1 + v2;
}
value_type* table_;
value_type dimension_;
};
value_type result = n_choose_k_impl(table, n).compute(n, k);
delete[] table;
return result;
}
//* 座標nx, nyがWidth,Heightの領域内にあるかどうかのチェック
inline bool rangeCheck2D(int nx, int ny, int Width, int Height)
{
return nx >= 0 and nx < Width and ny >= 0 and ny < Height;
}
//* bit全探索
/*
for (int i = 0; i < 1<<N; i++) {
REP(j, N)
if ((1 & i >> j) == 1) {;}
}
*/
namespace arc041a {
void arc041a()
{
cin >> X >> Y >> K;
if (K < Y)
cout << X + K << endl;
else
cout << X - (K - Y) + Y << endl;
}
}
// 優先度を付与してソート
namespace arc042a {
bool comp(const pair<int, int>& a, const pair<int, int>& b)
{
if (a.first == b.first)
return a.second > b.second;
else
return a.first < b.first;
}
void arc042a()
{
cin >> N >> M;
vector<pair<int, int>> ths(N);
REP(i, N) ths[i] = make_pair(0, i + 1);
REP(i, M) {
int a; cin >> a;
if (ths[a - 1].first == 0)
ths[a - 1].first = i + 1;
ths[a - 1].first = max(ths[a - 1].first, i + 1);
}
stable_sort(ths.rbegin(), ths.rend(), comp);
REP(i, N) {
cout << ths[i].second << endl;
}
}
}
namespace arc043a {
void arc043a()
{
cin >> N >> A >> B;
ll smax = 0, smin = INT32_MAX, sum = 0;
REP(i, N) {
ll s; cin >> s;
smax = max(smax, s);
smin = min(smin, s);
sum += s;
}
if (smax == smin)
cout << "-1" << endl;
else {
double diff = (double)smax - (double)smin;
double P = (double)B / diff;
double Q = (double)A - P * (double)sum / (double)N;
cout << setprecision(10) << P << " " << Q << endl;
}
}
}
namespace arc044a {
void arc044a()
{
cin >> N;
if (N == 1)
cout << "Not Prime" << endl;
else if (is_prime<unsigned>((unsigned)N))
cout << "Prime" << endl;
else {
string sin10 = to_string(N);
char iti = sin10[sin10.size() - 1];
int wa = 0;
REP(i, sin10.size())
wa += (int)(sin10[i] - '0');
if (iti != '5' and ((int)(iti - '0') % 2 != 0) and wa % 3 != 0)
cout << "Prime" << endl;
else
cout << "Not Prime" << endl;
}
}
}
namespace arc045a {
void arc045a()
{
}
}
int main()
{
arc044a::arc044a();
//arc013b::arc013b();
return 0;
}
Submission Info
Submission Time |
|
Task |
A - 素数判定 |
User |
xoke |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
5000 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
sample_04.txt |
AC |
1 ms |
256 KB |
test_01.txt |
AC |
1 ms |
256 KB |
test_02.txt |
AC |
1 ms |
256 KB |
test_03.txt |
AC |
1 ms |
256 KB |
test_04.txt |
AC |
1 ms |
256 KB |
test_05.txt |
AC |
1 ms |
256 KB |
test_06.txt |
AC |
1 ms |
256 KB |
test_07.txt |
AC |
1 ms |
256 KB |
test_08.txt |
AC |
1 ms |
256 KB |
test_09.txt |
AC |
1 ms |
256 KB |
test_10.txt |
AC |
1 ms |
256 KB |
test_11.txt |
AC |
1 ms |
256 KB |
test_12.txt |
AC |
1 ms |
256 KB |
test_13.txt |
AC |
1 ms |
256 KB |
test_14.txt |
AC |
1 ms |
256 KB |
test_15.txt |
AC |
1 ms |
256 KB |
test_16.txt |
AC |
1 ms |
256 KB |
test_17.txt |
AC |
1 ms |
256 KB |
test_18.txt |
AC |
1 ms |
256 KB |
test_19.txt |
AC |
1 ms |
256 KB |
test_20.txt |
AC |
1 ms |
256 KB |
test_21.txt |
AC |
1 ms |
256 KB |
test_22.txt |
AC |
1 ms |
256 KB |
test_23.txt |
AC |
1 ms |
256 KB |
test_24.txt |
AC |
1 ms |
256 KB |
test_25.txt |
AC |
1 ms |
256 KB |
test_26.txt |
AC |
1 ms |
256 KB |
test_27.txt |
AC |
1 ms |
256 KB |
test_28.txt |
AC |
1 ms |
256 KB |
test_29.txt |
AC |
1 ms |
256 KB |
test_30.txt |
AC |
1 ms |
256 KB |