- #include <bits/stdc++.h>
- using namespace std;
- #define llu long long unsigned
- llu c[2][2];
- int MOD;
- void mul(llu a[2][2],llu b[2][2]){
- memset(c, 0, sizeof(c));
- for(int i = 0; i <2; i++){
- for(int j = 0; j <2; j++){
- for(int k = 0; k <2; k++){
- c[i][j]+= ((a[i][k]%MOD)*(b[k][j]%MOD))%MOD;
- c[j][j]%=MOD;
- }
- }
- }
- for(int i = 0; i <2; i++){
- for(int j = 0; j <2; j++){
- a[i][j] = c[i][j]%MOD;
- }
- }
- }
- void ans(llu a[2][2], int n){
- llu m[2][2] = {{1, 1}, {1,0}};
- if(n == 1) return;
- ans(a, n/2);
- mul(a, a);
- if(n%2) mul(a, m);
- }
- int main(){
- int ts;
- scanf("%d", &ts);
- for(int p = 1; p <= ts; p++){
- llu f[2][2] = {{1, 1}, {1,0}};
- int a, b, n, m, answer;
- MOD = 1;
- scanf("%d%d%d%d",&a, &b, &n, &m);
- for(int i = 1; i<=m; i++) MOD*=10;
- if(n == 0) answer = a;
- else if(n == 1) answer = b;
- else if(n>1) ans(f, n-1), answer = (b*f[0][0]+a*f[0][1])%MOD;
- printf("Case %d: %d\n", p,answer%MOD );
- }
- return 0;
- }
Wednesday, 26 July 2017
lightoj 1065 Number sequence
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment