結果
| 問題 | 
                            No.954 Result
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2019-12-17 03:41:56 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1 ms / 2,000 ms | 
| コード長 | 908 bytes | 
| コンパイル時間 | 109 ms | 
| コンパイル使用メモリ | 22,912 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-04 12:35:21 | 
| 合計ジャッジ時間 | 1,009 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 7 | 
| other | AC * 29 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         for (int i = 1; i <= 5; i++) scanf("%lld", &a[i]);
      |                                      ~~~~~^~~~~~~~~~~~~~~
            
            ソースコード
#include <stdio.h>
long long int a[10];
long long int calc(long long int n) {
	long long int lst = 1, nxt = 1, now = 1;
	while (now < n) {
		nxt = now + lst;
		lst = now;
		now = nxt;
	}
	if (now == n) return lst;
	else return -1;
}
int main() {
	for (int i = 1; i <= 5; i++) scanf("%lld", &a[i]);
	if (a[5] == 1) {
		if (a[4] == 1) {
			for (int j = 3; j >= 1; j--) if (a[j] != a[j + 1] + a[j + 2]) {
				printf("%d\n", 5 - j);
				return 0;
			}
			printf("5\n");
		}
		else if (a[4] == 2) {
			for (int j = 3; j >= 1; j--) if (a[j] != a[j + 1] + a[j + 2]) {
				printf("%d\n", 5 - j);
				return 0;
			}
			printf("5\n");
		}
		else printf("1\n");
	}
	else {
		a[6] = calc(a[5]);
		if (a[6] == -1) printf("0\n");
		else {
			for (int j = 4; j >= 1; j--) if (a[j] != a[j + 1] + a[j + 2]) {
				printf("%d\n", 5 - j);
				return 0;
			}
			printf("5\n");
		}
	}
}