QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#93774 | #6148. 宝石项圈 | Renshey | 100 ✓ | 3ms | 5332kb | C++23 | 604b | 2023-04-02 10:38:10 | 2023-04-02 10:38:12 |
Judging History
answer
#include <bits/stdc++.h>
const int maxn = 120000 + 10;
int n;
long long p, f[maxn], g[maxn];
inline long long Mod(long long x, long long y, long long p) { return x + y >= p ? x + y - p : x + y; }
signed main()
{
while (~scanf("%d%lld", &n, &p))
{
if (n == 1)
{
puts("1");
continue;
}
if (n == 2)
{
printf("%lld\n", 2 % p);
continue;
}
f[0] = 0;
g[0] = 1;
f[1] = 1;
g[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = Mod(f[i - 1], g[i - 2], p), g[i] = Mod(g[i - 1], f[i - 2], p);
printf("%lld\n", Mod(g[n - 3], f[n - 1], p));
}
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 3580kb
input:
476 1000000007 22 1000000007 459 1000000007 276 1000000007 342 1000000007 358 1000000007 337 1000000007 320 1000000007 486 1000000007 413 1000000007 93 1000000007 208 1000000007 114 1000000007 302 1000000007 35 1000000007
output:
34286320 19802 419493257 882763980 491018914 284811677 1753852 618944076 425499304 915474585 825927387 4521939 921766975 161691736 10316619
result:
ok 15 lines
Test #2:
score: 10
Accepted
time: 2ms
memory: 3564kb
input:
87 1000000007 20 1000000007 17 1000000007 229 1000000007 90 1000000007 295 1000000007 356 1000000007 97 1000000007 324 1000000007 255 1000000007 64 1000000007 206 1000000007 172 1000000007 321 1000000007 405 1000000007
output:
225802125 7564 1785 549719541 650031318 386657859 722254332 343574945 975090319 937796991 575165670 685276405 760753532 912400731 257871201
result:
ok 15 lines
Test #3:
score: 10
Accepted
time: 1ms
memory: 3616kb
input:
172 1000000007 334 1000000007 466 1000000007 283 1000000007 125 1000000007 86 1000000007 244 1000000007 24 1000000007 142 1000000007 477 1000000007 218 1000000007 351 1000000007 227 1000000007 42 1000000007 77 1000000007
output:
760753532 189041386 791717973 256376117 528027886 986312481 430198871 51840 945295649 241086629 960957163 34752130 356511318 299537288 430086117
result:
ok 15 lines
Test #4:
score: 10
Accepted
time: 1ms
memory: 3880kb
input:
3841 1000000007 11443 1000000007 1501 1000000007 11088 1000000007 85 1000000007 13560 1000000007 12878 1000000007 1439 1000000007 449 1000000007 9165 1000000007 4833 1000000007 19722 1000000007 9268 1000000007 18101 1000000007 15235 1000000007
output:
940222347 628093551 789534976 130988819 239489650 645812897 16272396 830292992 183556690 171614628 147559486 33824760 256975033 435969885 801761986
result:
ok 15 lines
Test #5:
score: 10
Accepted
time: 2ms
memory: 4088kb
input:
3936 1000000007 15467 1000000007 8041 1000000007 796 1000000007 4295 1000000007 9131 1000000007 4835 1000000007 14852 1000000007 7765 1000000007 14711 1000000007 544 1000000007 999 1000000007 15936 1000000007 6425 1000000007 3447 1000000007
output:
78745510 346699774 850096917 580474572 984606324 153733379 538986001 178302695 927779645 763296885 214940686 722747442 324084182 175476387 100584386
result:
ok 15 lines
Test #6:
score: 10
Accepted
time: 3ms
memory: 5188kb
input:
334 1000000007 466 1000000007 283 1000000007 125 1000000007 100450 1000000007 218 1000000007 351 1000000007
output:
189041386 791717973 256376117 528027886 803901258 960957163 34752130
result:
ok 7 lines
Test #7:
score: 10
Accepted
time: 0ms
memory: 5332kb
input:
356 1000000007 97 1000000007 112226 1000000007 206 1000000007 172 1000000007
output:
722254332 343574945 598557873 685276405 760753532
result:
ok 5 lines
Test #8:
score: 10
Accepted
time: 1ms
memory: 4320kb
input:
45082 1000000007 11505 1000000007 459 1000000007 276 1000000007 342 1000000007
output:
285219503 420419622 419493257 882763980 491018914
result:
ok 5 lines
Test #9:
score: 10
Accepted
time: 1ms
memory: 4688kb
input:
208 1000000007 114 1000000007 302 1000000007 68977 1000000007 342 1000000007 358 1000000007
output:
4521939 921766975 161691736 578817144 491018914 284811677
result:
ok 6 lines
Test #10:
score: 10
Accepted
time: 2ms
memory: 3976kb
input:
206 1000000007 172 1000000007 9885 1000000007 321 1000000007 405 1000000007
output:
685276405 760753532 189342921 912400731 257871201
result:
ok 5 lines