Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 698 | Codeforces Round 363 (Div. 1) | FINISHED | False | 8100 | 307472123 | July 19, 2016, 1:05 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 487 ) | F | Coprime Permutation | PROGRAMMING | combinatorics number theory | 3000 |
Two positive integers are coprime if and only if they don't have a common divisor greater than 1. Some bear doesn't want to tell Radewoosh how to solve some algorithmic problem. So, Radewoosh is going to break into that bear's safe with solutions. To pass through the door, he must enter a permutation of numbers 1 through n. The door opens if and only if an entered permutation p1, p2, ..., pn satisfies: In other words, two different elements are coprime if and only if their indices are coprime. Some elements of a permutation may be already fixed. In how many ways can Radewoosh fill the remaining gaps so that the door will open? Print the answer modulo 109 + 7. The first line of the input contains one integer n (2 ≤ n ≤ 1 000 000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n) where pi = 0 means a gap to fill, and pi ≥ 1 means a fixed number. It's guaranteed that if i ≠ j and pi, pj ≥ 1 then pi ≠ pj. Print the number of ways to fill the gaps modulo 109 + 7 (i.e. modulo 1000000007). In the first sample test, none of four element is fixed. There are four permutations satisfying the given conditions: (1,2,3,4), (1,4,3,2), (3,2,1,4), (3,4,1,2). In the second sample test, there must be p3 = 1 and p4 = 2. The two permutations satisfying the conditions are: (3,4,1,2,5), (5,4,1,2,3). |
| Solution |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 29154650 | Scut82 | F | Aug. 3, 2017, 11:57 a.m. | OK | GNU C++ | TESTS | 37 | 156 | 30208000 | 3000 | |
| 26238758 | jiyutian | F | April 9, 2017, 1:59 p.m. | OK | GNU C++ | TESTS | 37 | 187 | 38400000 | 3000 | |
| 28058217 | DraZxlNDdt | F | June 26, 2017, 1:13 p.m. | OK | GNU C++ | TESTS | 37 | 249 | 32153600 | 3000 | |
| 28058303 | DraZxlNDdt | F | June 26, 2017, 1:18 p.m. | OK | GNU C++ | TESTS | 37 | 264 | 31948800 | 3000 | |
| 28058249 | DraZxlNDdt | F | June 26, 2017, 1:15 p.m. | OK | GNU C++ | TESTS | 37 | 264 | 32153600 | 3000 | |
| 28057289 | H4XeO6 | F | June 26, 2017, 12:25 p.m. | OK | GNU C++ | TESTS | 37 | 264 | 49971200 | 3000 | |
| 28057272 | H4XeO6 | F | June 26, 2017, 12:24 p.m. | OK | GNU C++ | TESTS | 37 | 264 | 49971200 | 3000 | |
| 28052327 | DraZxlNDdt | F | June 26, 2017, 8 a.m. | OK | GNU C++ | TESTS | 37 | 280 | 32153600 | 3000 | |
| 25966087 | FHW_SO_WALL | F | March 31, 2017, 1:20 a.m. | OK | GNU C++ | TESTS | 37 | 296 | 66048000 | 3000 | |
| 19253678 | gs12117 | F | July 19, 2016, 3:02 p.m. | OK | GNU C++ | TESTS | 36 | 311 | 31948800 | 3000 | |
| 53897985 | Isonan | F | May 9, 2019, 7:21 a.m. | OK | GNU C++11 | TESTS | 37 | 124 | 40857600 | 3000 | |
| 40984032 | ReaLNero1 | F | July 30, 2018, 7:09 p.m. | OK | GNU C++11 | TESTS | 37 | 140 | 32051200 | 3000 | |
| 40482389 | Scut82 | F | July 17, 2018, 2:45 p.m. | OK | GNU C++11 | TESTS | 37 | 140 | 32051200 | 3000 | |
| 54503259 | WOSHIGEPACHONG2 | F | May 23, 2019, 12:55 a.m. | OK | GNU C++11 | TESTS | 37 | 140 | 40857600 | 3000 | |
| 53897947 | Isonan | F | May 9, 2019, 7:20 a.m. | OK | GNU C++11 | TESTS | 37 | 140 | 40857600 | 3000 | |
| 28052741 | ihopenot | F | June 26, 2017, 8:20 a.m. | OK | GNU C++11 | TESTS | 37 | 171 | 46182400 | 3000 | |
| 28076438 | h10 | F | June 27, 2017, 12:42 p.m. | OK | GNU C++11 | TESTS | 37 | 187 | 27136000 | 3000 | |
| 38650709 | 131441373 | F | May 27, 2018, 8:15 a.m. | OK | GNU C++11 | TESTS | 37 | 202 | 40038400 | 3000 | |
| 19363195 | krijgertje | F | July 23, 2016, 10:55 a.m. | OK | GNU C++11 | TESTS | 37 | 249 | 32051200 | 3000 | |
| 21609468 | tfg | F | Oct. 20, 2016, 5:49 a.m. | OK | GNU C++11 | TESTS | 37 | 265 | 35123200 | 3000 | |
| 32745980 | whzzt | F | Nov. 28, 2017, 10:02 a.m. | OK | GNU C++14 | TESTS | 37 | 140 | 37376000 | 3000 | |
| 28057060 | Gintoki | F | June 26, 2017, 12:12 p.m. | OK | GNU C++14 | TESTS | 37 | 233 | 57241600 | 3000 | |
| 32745732 | AmberFrame | F | Nov. 28, 2017, 9:49 a.m. | OK | GNU C++14 | TESTS | 37 | 264 | 33996800 | 3000 | |
| 57443679 | Scut82 | F | July 21, 2019, 7:34 a.m. | OK | GNU C++14 | TESTS | 37 | 327 | 28057600 | 3000 | |
| 57482151 | Scut82 | F | July 22, 2019, 2:59 a.m. | OK | GNU C++14 | TESTS | 37 | 327 | 32051200 | 3000 | |
| 28054426 | liu_runda | F | June 26, 2017, 9:42 a.m. | OK | GNU C++14 | TESTS | 37 | 327 | 47001600 | 3000 | |
| 26815042 | Navick | F | May 3, 2017, 8:15 a.m. | OK | GNU C++14 | TESTS | 37 | 358 | 35020800 | 3000 | |
| 39508813 | xyj | F | June 22, 2018, 7:39 a.m. | OK | GNU C++14 | TESTS | 37 | 374 | 41062400 | 3000 | |
| 35224510 | cyz666 | F | Feb. 14, 2018, 6:48 a.m. | OK | GNU C++14 | TESTS | 37 | 420 | 42086400 | 3000 | |
| 28052361 | LoveYayoi | F | June 26, 2017, 8:02 a.m. | OK | GNU C++14 | TESTS | 37 | 421 | 84070400 | 3000 | |
| 56769284 | Shayan.P | F | July 9, 2019, 8:23 p.m. | OK | GNU C++17 | TESTS | 37 | 405 | 28057600 | 3000 | |
| 57560084 | Benq | F | July 22, 2019, 11:32 p.m. | OK | GNU C++17 | TESTS | 37 | 576 | 59392000 | 3000 | |
| 19251963 | Egor | F | July 19, 2016, 2:50 p.m. | OK | Java 8 | TESTS | 36 | 311 | 46592000 | 3000 | |
| 21129384 | _fake- | F | Oct. 3, 2016, 6:06 a.m. | OK | Java 8 | TESTS | 37 | 499 | 56729600 | 3000 | |
| 19249451 | Petr | F | July 19, 2016, 2:33 p.m. | OK | Java 8 | TESTS | 36 | 529 | 74752000 | 3000 | |
| 19430140 | mmaxio | F | July 26, 2016, 9:48 p.m. | OK | Java 8 | TESTS | 37 | 701 | 46899200 | 3000 | |
| 19255248 | DEGwer | F | July 19, 2016, 3:13 p.m. | OK | MS C++ | TESTS | 36 | 764 | 63078400 | 3000 | |
| 19558651 | Los_Angelos_Laycurse | F | Aug. 1, 2016, 11:10 a.m. | OK | MS C++ | TESTS | 37 | 795 | 71065600 | 3000 | |
| 19257429 | DEGwer | F | July 19, 2016, 5 p.m. | OK | MS C++ | TESTS | 36 | 857 | 67072000 | 3000 |
Back to search problems