zoukankan      html  css  js  c++  java
  • P1045 麦森数

    别问我为什么要写水题

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    typedef long long ll;
    const int N = 505;
    
    struct meow {
        int a[N], n;
        int& operator [](int x) {return a[x];}
        meow(int x = 0) {n = 1; memset(a, 0, sizeof(a)); a[1] = x;}
    } ;
    
    meow operator *(meow &a, meow &b) {
        const int B = 10;
        meow c;
        for(int i=1; i<=a.n; i++) {
            int g=0;
            for(int j=1; j<=b.n; j++) if(i+j-1 <= 500)
                g += c[i+j-1]+a[i]*b[j], c[i+j-1] = g%B, g/=B;
            if(i + b.n <= 500) c[i+b.n] = g;
        }
        c.n = min(500, a.n + b.n); 
        while(c.n>1 && c[c.n]==0) c.n--;
        return c;
    }
    
    meow operator ^(meow a, int b) {
        meow ans(1);
        for(; b; b >>= 1, a = a * a) 
            if(b & 1) ans = ans * a;
        return ans;
    }
    
    int n;
    int main() {
        //freopen("in", "r", stdin);
        scanf("%d", &n);
        meow a(2);
        a = a ^ n; a[1]--;
    
        printf("%.0lf
    ", floor(n * log10(2) + 1));
        for(int i=500; i > a.n; i--) putchar('0'), i % 50 == 1 ? puts("") : 1+1;
        for(int i=a.n; i>=1; i--) putchar(a[i] + '0'), i % 50 == 1 ? puts("") : 1+1;
    }
    
  • 相关阅读:
    Comet OJ
    Comet OJ
    Comet OJ
    Comet OJ
    Codeforces Round #562 (Div. 2)
    P1202 USACO1.1 黑色星期五
    P1201 USACO1.1 贪婪的送礼者
    【线段树】HDU1166:敌兵布阵
    标准C++中的string类的用法总结(转)
    【递归】分形
  • 原文地址:https://www.cnblogs.com/candy99/p/6785504.html
Copyright © 2011-2022 走看看