|
发表于 2023-1-27 10:59:52
|
显示全部楼层
很可能是因为数据不够大,毕竟只有 A 只有1000位
下面的测试里 A 恰好有 1e7 位,而 B 是 1999999999
- $ cat test.cpp
- #include <iostream>
- #include <boost/multiprecision/cpp_int.hpp>
- using boost::multiprecision::cpp_int;
- int main() {
- cpp_int a, b;
- std::cin >> a >> b;
- std::cout << a % b << std::endl;
- return 0;
- }%
- $ clang++ test.cpp
- $ /usr/bin/time -p timeout -v 0.5s ./a.out < input
- timeout: sending signal TERM to command ‘./a.out’
- real 0.50
- user 0.49
- sys 0.00
- $ cat test2.cpp
- #include <iostream>
- #include <string>
- int main(){
- std::string a;
- uint64_t b;
- uint64_t result = 0;
- std::cin >> a >> b;
- for(const auto c: a){
- result = ((result << 3) + (result << 1) + (c - '0')) % b;
- }
- std::cout << result;
- return 0;
- }%
- $ clang++ test2.cpp
- $ /usr/bin/time -p timeout -v 0.5s ./a.out < input
- 1313860644
- real 0.13
- user 0.13
- sys 0.00
- $ cat test3.cpp
- #include <cstdio>
- #include <cstring>
- char a[10000005];
- int n, p;
- long long eval_ans() {
- long long x = 1, avalue = 0;
- for (int i = n; i >= 1; --i) {
- long long ap = (long long)(a[i] - '0') * x;
- ap %= p;
- avalue += ap;
- avalue %= p;
- x *= 10;
- x %= p;
- }
- return avalue;
- }
- int main() {
- scanf("%s%d", a + 1, &p);
- n = strlen(a + 1);
- printf("%lld", eval_ans());
- }
- $ clang++ test3.cpp
- $ /usr/bin/time -p timeout -v 0.5s ./a.out < input
- 1313860644
- real 0.07
- user 0.07
- sys 0.00
- $ cat test.c
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- int main(){
- enum{ BufferSize = 1024 };
- struct stat status;
- unsigned char buffer[BufferSize];
- ssize_t effective_length;
- if(fstat(STDIN_FILENO, &status) == -1){
- return 1;
- }
- off_t seek_offset = status.st_size > 11 ? -11 : -status.st_size;
- if(lseek(STDIN_FILENO, seek_offset, SEEK_END) == -1){
- return 1;
- }
- effective_length = read(STDIN_FILENO, buffer, BufferSize);
- unsigned long b = 0;
- ssize_t i = 0;
- while(buffer[i++] != ' ');
- while(i < effective_length && buffer[i] >= '0' && buffer[i] <= '9'){
- b = (b << 3) + (b << 1) + (buffer[i++] - '0');
- }
- lseek(STDIN_FILENO, 0, SEEK_SET);
- unsigned long result = 0;
- effective_length = i = 0;
- while(1){
- effective_length = read(STDIN_FILENO, buffer, BufferSize);
- for(i = 0; i < effective_length; i++){
- if(buffer[i] == ' ') goto end;
- result = ((result << 3) + (result << 1) + (buffer[i] - '0')) % b;
- }
- }
- end:
- i = 12;
- effective_length = 0;
- if(result == 0){
- effective_length = 1;
- buffer[i--] = '0';
- }
- while(result){
- effective_length++;
- buffer[i--] = (result % 10) + '0';
- result /= 10;
- }
- write(STDOUT_FILENO, buffer + i + 1, effective_length);
- return 0;
- }%
- $ clang test.c
- $ /usr/bin/time -p timeout -v 0.5s ./a.out < input
- 1313860644
- real 0.03
- user 0.02
- sys 0.00
复制代码 |
评分
-
查看全部评分
|