QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#817139 | #7033. Resistors in Parallel | SGColin | AC ✓ | 2ms | 4060kb | C++17 | 2.5kb | 2024-12-16 20:36:52 | 2024-12-16 20:36:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
const int prime[200] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
struct num {
int len, a[200];
inline void reset() {
memset(a, 0, sizeof(a));
a[len = 1] = 1;
}
inline bool operator >= (const num &obj) const {
if (len != obj.len) return len > obj.len;
for (int i = len; i; --i)
if (a[i] != obj.a[i]) return a[i] > obj.a[i];
return true;
}
inline void read() {
len = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) {
a[++len] = c - '0';
c = getchar();
}
reverse(a + 1, a + 1 + len);
}
inline void mul(int x) {
int rem = 0;
for (int i = 1; i <= len; ++i) {
a[i] = a[i] * x + rem;
rem = a[i] / 10;
a[i] = a[i] % 10;
}
while (rem) {
a[++len] = rem % 10;
rem /= 10;
}
}
void print() {
for (int i = len; i; --i) printf("%d", a[i]);
}
} N, A, B;
inline void work() {
N.read();
A.reset();
int ptr = 0;
while (N >= A) A.mul(prime[++ptr]);
--ptr;
if (ptr == 0) {puts("1/1"); return;}
vector<int> up, dn;
rep(i, 1, ptr) {
up.push_back(prime[i]);
dn.push_back(prime[i] + 1);
}
A.reset();
B.reset();
for (auto x : up) {
bool fl = false;
for (auto &y : dn)
if (y % x == 0) {
y /= x; fl = true; break;
}
if (!fl) A.mul(x);
}
for (auto x : dn) B.mul(x);
A.print(); putchar('/'); B.print(); puts("");
}
int main() {
int t = rd();
while (t--) work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3700kb
input:
3 10 100 1000
output:
1/2 5/12 35/96
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
100 9055 764034929998350 175478445981 3066144 373717 79921483664325743 31787974933 19712134724867403 86665280597 9459527960934 45840 6831794283 631941163719 8241229170655 992693590670671467 288745916793799209 83790620689711 21805764718032208 5455 39 909 3 79423683 43 198853556983437047 5221603522064...
output:
385/1152 76253198879/321052999680 30808063/119439360 12155/41472 715/2304 298080686527/1284211998720 30808063/119439360 298080686527/1284211998720 30808063/119439360 1859834119/7644119040 715/2304 30808063/119439360 955049953/3822059520 1859834119/7644119040 14009792266769/61642175938560 29808068652...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 4060kb
input:
100 179305586963 96883378626478880429056246520023290774722301848230232935789122 161758308595898 178124354133226622987953243895918403851 1893414732443742551436 61239961784411409687653066831224920774024514762604245 2305567963945518424753102147331756069 619035744750559608675 8749921888120 4072968059924...
output:
30808063/119439360 1749936537208721528520879643954955339690231858377/9753327077118246544899138751790948391321600000000 1859834119/7644119040 2694014995838881344684929537/13636826284246500397547520000 742518990138757/3328677500682240 47269280380971678953725754621107734221741/2546294662990352585865481...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 3700kb
input:
100 22939325522365660014467787481973310847349569760706025172732597301326936494429523296729661721 7029461483963351683658343686551075543421117918728658657046178242960651103186293515 33800318667247027732146374420765580419884087620966241732522617435712471851616225196963088465984970 242755330487870550410...
output:
154395010617978451305968882287268454695382683719518660706078042712504201/920479896805919917804276884737662765142862669596588016402432000000000000 16811536080563707769953565248128113493150676390734314896696553/97952070308873397595155186362822686508099250929270784000000000 8597794956283366017875489147...
result:
ok 100 lines