結果

問題 No.720 行列のできるフィボナッチ数列道場 (2)
ユーザー testestesttestestest
提出日時 2018-07-29 00:40:15
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 29,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 20:42:53
合計ジャッジ時間 1,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 0 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 0 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:10:4: 警告: conflicting types for built-in function ‘pow’; expected ‘double(double,  double)’ [-Wbuiltin-declaration-mismatch]
   10 | r5 pow(r5 a,ll n){r5 x={1,0};for(;n;n/=2,a=mul(a,a))if(n&1)x=mul(x,a);return x;}
      |    ^~~
main.c:1:1: 備考: ‘pow’ is declared in header ‘<math.h>’
  +++ |+#include <math.h>
    1 | #define ll long long
main.c: 関数 ‘main’ 内:
main.c:25:9: 警告: 関数 ‘scanf’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   25 |         scanf("%lld%lld",&n,&m);
      |         ^~~~~
main.c:1:1: 備考: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | #define ll long long
main.c:25:9: 警告: 組み込み関数 ‘scanf’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
   25 |         scanf("%lld%lld",&n,&m);
      |         ^~~~~
main.c:25:9: 備考: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
main.c:26:9: 警告: 関数 ‘printf’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   26 |         printf("%lld",(f(phi,n,m)-f(varphi,n,m)+M+M)%M);
      |         ^~~~~~
main.c:26:9: 備考: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:26:9: 警告: 組み込み関数 ‘printf’ の互換性がない暗黙的な宣言です [-Wbuiltin-declaration-mismatch]
main.c:26:9: 備考: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #

#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)

#define M 1000000007
ll pom(ll a,ll n){ll x=1;for(a%=M;n;n/=2,a=a*a%M)if(n&1)x=x*a%M;return x;}
#define invp(a)pom(a,M-2)

typedef struct r5{ll a,b;}r5;
r5 mul(r5 x,r5 y){r5 z={(x.a*y.a+x.b*y.b*5)%M,(x.a*y.b+x.b*y.a)%M};return z;}
r5 pow(r5 a,ll n){r5 x={1,0};for(;n;n/=2,a=mul(a,a))if(n&1)x=mul(x,a);return x;}
r5 inv(r5 x){ll d=invp(x.a*x.a-5*x.b*x.b);x.a=x.a*d%M;x.b=-x.b*d%M;return x;}

ll f(r5 x,ll n,ll m){
	r5 t1=pow(x,n*m);
	t1.a--;
	r5 t2=pow(x,m);
	t2.a--;
	return mul(pow(x,m),mul(t1,inv(t2))).b;
}

int main(){
	r5 phi={(M+1)/2,(M+1)/2};
	r5 varphi={(M+1)/2,-(M+1)/2};
	ll n,m;
	scanf("%lld%lld",&n,&m);
	printf("%lld",(f(phi,n,m)-f(varphi,n,m)+M+M)%M);
}
0