多校-HDU 5351 MZL's Border 數學

來源:互聯網
上載者:User

標籤:

f[1] = ‘b‘, f[2] = ‘a‘, f[i] = f[i - 1] + f[i - 2]

斐波那契數列的字串,給你n和m,前m位中,最長的首碼等於尾碼的長度是多少。1≤n≤1000, 1≤m≤length(f[n])

規律題,雖然我不知道為什麼。

 1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 public class Main{ 5     //Scanner cin = Scanner(System.in); 6     static BigInteger f[] = new BigInteger[1005]; 7     public static void main(String[] args){ 8         f[1] = new BigInteger("1"); 9         f[2] = new BigInteger("2");10         for(int i = 3; i <= 1001; i++){11             //f[i].valueOf(f[i - 1);12             //f[i] = f[i - 1];13             f[i] = f[i - 1].add(f[i - 2]);14             //f[i].add(f[i - 2]);15             //System.out.println(f[i]);16         }17         Scanner cin = new Scanner(System.in);18         int T = cin.nextInt();19         int n;20         BigInteger m;21         for(int cas = 1; cas <= T; cas++){22             n = cin.nextInt();23             m = cin.nextBigInteger();24             BigInteger mm = m.add(new BigInteger("1"));25             int p = 0;26             for(int i = 1; i <= 1001; i++){27                 if(f[i].compareTo(mm) > 0){28                     p = i;29                     break;30                 }31             }32             BigInteger ans = m.subtract(f[p - 2]);33             System.out.println(ans.mod(new BigInteger("258280327")));34         }35         36     }37 }

 

多校-HDU 5351 MZL's Border 數學

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.