CSES - Putka Open 2015 – 4/6 - Results
Submission details
Task:Taulukot
Sender:
Submission time:2015-10-11 19:04:13 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED26
#2ACCEPTED29
#3ACCEPTED45
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.06 s1details
#4ACCEPTED0.06 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.05 s2details
#7ACCEPTED0.05 s2details
#8ACCEPTED0.06 s2details
#9ACCEPTED0.06 s2details
#10ACCEPTED0.06 s2details
#11ACCEPTED0.06 s3details
#12ACCEPTED0.06 s3details
#13ACCEPTED0.06 s3details
#14ACCEPTED0.06 s3details
#15ACCEPTED0.07 s3details

Code

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<utility>

using namespace std;

__uint128_t power_mod128(__uint128_t a, uint64_t k, uint64_t m) {
  if(k == 0) return 1;
  __uint128_t res=power_mod128(a, k/2, m);
  if(k%2 == 0) return res*res%m;
  return res*a%m*res%m;
}

bool is_witness(uint64_t a, uint64_t evenpart, uint64_t oddpart, uint64_t p) {
  __uint128_t u = power_mod128(a, oddpart, p);
  if(u == 1) return false;
  for(uint64_t j=1;j<evenpart;j*=2) {
    if(u == p-1) return false;
    u*=u; u%=p;
  }
  return true;
}

bool miller_rabin64(uint64_t p) {
  uint64_t odd=p-1;
  uint64_t even=1;
  while(odd%2 == 0) { even*=2; odd/=2; }
  const int64_t bases[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  for(uint64_t i=0;i<7;i++) {
    uint64_t a = bases[i]%p;
    if(a == 0) return true;
    if(is_witness(a, even, odd, p)) return false;
  }
  return true;
}

int main(void) {
  int64_t n;
  cin >> n;
  vector<int64_t> a,b;
  while(n > 0) {
    int64_t p=n+1;
    for(;p<2*n;p++) {
      if(miller_rabin64(p)) break;
    }
    for(int64_t k=n;k>=p-n;k--) {
      a.push_back(k);
      b.push_back(p-k);
    }
    n=p-n-1;
  }
  for(auto x: a) {
    cout << x << " ";
  }
  cout << "\n";
  for(auto y: b) {
    cout << y << " ";
  }
  cout << "\n";
  return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1

correct output


user output


Test 2

Group: 1

Verdict: ACCEPTED

input
4

correct output
1 2 3 4 
2 1 4 3 

user output
4 3 2 1 
1 2 3 4 

Test 3

Group: 1

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
1 5 4 3 2 

user output
5 4 3 2 1 
2 3 4 5 1 

Test 4

Group: 1

Verdict: ACCEPTED

input
8

correct output
1 2 3 4 5 6 7 8 
2 1 4 3 8 7 6 5 

user output
8 7 6 5 4 3 2 1 
3 4 5 6 7 8 1 2 

Test 5

Group: 1

Verdict: ACCEPTED

input
9

correct output
1 2 3 4 5 6 7 8 9 
1 5 4 3 2 7 6 9 8 

user output
9 8 7 6 5 4 3 2 1 
2 3 4 5 6 7 8 9 1 

Test 6

Group: 2

Verdict: ACCEPTED

input
77

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
77 76 75 74 73 72 71 70 69 68 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
70

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
70 69 68 67 66 65 64 63 62 61 ...

Test 8

Group: 2

Verdict: ACCEPTED

input
72

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
72 71 70 69 68 67 66 65 64 63 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
86

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
86 85 84 83 82 81 80 79 78 77 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
68

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
68 67 66 65 64 63 62 61 60 59 ...

Test 11

Group: 3

Verdict: ACCEPTED

input
90764

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
90764 90763 90762 90761 90760 ...

Test 12

Group: 3

Verdict: ACCEPTED

input
97976

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
97976 97975 97974 97973 97972 ...

Test 13

Group: 3

Verdict: ACCEPTED

input
96762

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
96762 96761 96760 96759 96758 ...

Test 14

Group: 3

Verdict: ACCEPTED

input
94823

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
94823 94822 94821 94820 94819 ...

Test 15

Group: 3

Verdict: ACCEPTED

input
91479

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
91479 91478 91477 91476 91475 ...