結果
問題 | No.152 貯金箱の消失 |
ユーザー |
![]() |
提出日時 | 2015-02-17 16:20:37 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 54 ms / 5,000 ms |
コード長 | 1,139 bytes |
コンパイル時間 | 539 ms |
コンパイル使用メモリ | 56,060 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 20:16:53 |
合計ジャッジ時間 | 1,278 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <iostream>using namespace std;int gcd( int m, int n );int main(int argc, const char * argv[]) {int L;cin >> L;int m = 2, n = 1;long long count = 0;while (true) {if(m <= n){m++;n = 1;continue;}else if((m-n) % 2 != 1){n++;continue;}else if(gcd(m,n) != 1){n++;continue;}int a = m*m - n*n;int b = 2 * m * n;int c = m*m + n*n;if((a+b+c)*4 <= L){count++;}if((m*m + 1) * 4 > L){break;}//cout << m << " " << n << " " << a + b + c << endl;n++;}cout << count % 1000003 << endl;return 0;}int gcd( int m, int n ){// 引数に0がある場合は0を返すif ( ( 0 == m ) || ( 0 == n ) )return 0;// ユークリッドの方法while( m != n ){if ( m > n ) m = m - n;else n = n - m;}return m;}