zoukankan      html  css  js  c++  java
  • HDU6198

    number number number

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 118    Accepted Submission(s): 79


    Problem Description

    We define a sequence F:

     F0=0,F1=1;
     Fn=Fn1+Fn2 (n2).

    Give you an integer k, if a positive number n can be expressed by
    n=Fa1+Fa2+...+Fak where 0a1a2ak, this positive number is mjfgood. Otherwise, this positive number is mjfbad.
    Now, give you an integer k, you task is to find the minimal positive mjfbad number.
    The answer may be too large. Please print the answer modulo 998244353.
     

    Input

    There are about 500 test cases, end up with EOF.
    Each test case includes an integer k which is described above. (1k109)
     

    Output

    For each case, output the minimal mjfbad number mod 998244353.
     

    Sample Input

    1
     

    Sample Output

    4
     

    Source

     
    ans = F(2*n+1)-1
     
     1 //2017-09-10
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 #define LL long long
     7 #define MAXN 100
     8 
     9 using namespace std;
    10 
    11 const int MOD = 998244353;
    12 
    13 struct Matrix  
    14 {  
    15     LL a[MAXN][MAXN];  
    16     int r, c; 
    17 };  
    18 
    19 Matrix ori, res; 
    20 
    21 void init()  
    22 {  
    23     memset(res.a, 0, sizeof(res.a));  
    24     res.r = 2; res.c = 2;  
    25     for(int i = 1; i <= 2; i++)  
    26       res.a[i][i] = 1;  
    27     ori.r = 2; ori.c = 2;  
    28     ori.a[1][1] = ori.a[1][2] = ori.a[2][1] = 1;  
    29     ori.a[2][2] = 0;  
    30 }  
    31 
    32 Matrix multi(Matrix x, Matrix y)  
    33 {  
    34     Matrix z;  
    35     memset(z.a, 0, sizeof(z.a));  
    36     z.r = x.r, z.c = y.c;    
    37     for(int i = 1; i <= x.r; i++) 
    38     {  
    39         for(int k = 1; k <= x.c; k++)      
    40         {  
    41             if(x.a[i][k] == 0) continue;
    42             for(int j = 1; j<= y.c; j++)  
    43               z.a[i][j] = (z.a[i][j] + (x.a[i][k] * y.a[k][j]) % MOD) % MOD;  
    44         }  
    45     }  
    46     return z;  
    47 }  
    48 void Matrix_mod(int n)  
    49 {  
    50     while(n)  
    51     {  
    52         if(n & 1)  
    53           res = multi(ori, res);  
    54         ori = multi(ori, ori);  
    55         n >>= 1;  
    56     }  
    57     printf("%lld
    ", res.a[1][2]-1 % MOD);  
    58 }  
    59 
    60 int main()
    61 {
    62     int k;
    63     while(scanf("%d", &k) != EOF)
    64     {
    65         init();
    66         k++;
    67         Matrix_mod(2*k+1);
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    图数据库-Neo4j使用
    [原创]networkx 画中文节点
    python networkx:绘制网络图
    Python二维数组,坑苦了
    xgboost
    python 机器学习
    计算机网络知识
    前端优化不完全指南(转)
    FlashFXP 4.3.1 注册码
    你真的会使用Chrome开发者工具吗?
  • 原文地址:https://www.cnblogs.com/Penn000/p/7502280.html
Copyright © 2011-2022 走看看