結果
問題 |
No.251 大きな桁の復習問題(1)
|
ユーザー |
![]() |
提出日時 | 2015-07-25 11:36:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 813 bytes |
コンパイル時間 | 1,402 ms |
コンパイル使用メモリ | 159,732 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-17 17:23:05 |
合計ジャッジ時間 | 2,159 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%s", N); | ~~~~~^~~~~~~~~ main.cpp:11:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%s", M); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> int main() { char N[1048576]; char M[1048576]; uint64_t p = 129402307; scanf("%s", N); scanf("%s", M); int N_size = strlen(N); int M_size = strlen(M); uint64_t n = 0; uint64_t m = 0; if( N_size == 1 and N[0] == '0' ) { printf("0\n"); return 0; } if( M_size == 1 and M[0] == '0' ) { printf("1\n"); return 0; } for(int i = 0; i < N_size; ++i) { n = (n * 10 + (N[i] - '0')) % p; } for(int i = 0; i < M_size; ++i) { m = (m * 10 + (M[i] - '0')) % (p - 1); } if( n == 0 ) { printf("0\n"); return 0; } uint64_t ans = 1; while( m != 0 ) { if( (m & 0x01) != 0 ) { ans = (ans * n) % p; } n = (n * n) % p; m >>= 1; } printf("%ld\n", ans); return 0; }