179 条题解

  • 1
    @ 2020-03-05 00:02:50
    //用dp做了半天(只得了12分), 才知道有这个数学定理...
    //通过一个数学定理,得:将这几个数分解成和e无限接近的数,相乘可取到最大值。所以尽量取3。
    #include <iostream>                 //整数分解(版本2)
    #include <algorithm>
    #include <cstring>
    using namespace std;
    const int MaxN = 100;
    
    int num[MaxN];
    int len = 1;
    
    void Print(int num[], int n)        //输出数组值
    {
        for (int i = n; i >= 1; i--)
            cout << num[i];
        cout << endl;
    }
    
    void Mul_n_num(int num[], int n)    //数组与数字相乘
    {
        int add = 0;
        for (int i = 1; i <= len; i++)
        {
            int t = (n * num[i] + add);
            num[i] = t % 10;
            add = t / 10;
        }
        if(add)
            num[++len] = add;
    }
    
    void Dis_int(int n)                 //分解整数
    {
        int ans;
        if (n == 1 || n == 2 || n == 3 || n == 4)
            num[1] = n;
        else
        {
            ans = n / 3;
            if (n % 3 == 2)
                num[1] = 2;
            else if(n % 3 == 0)
                num[1] = 1;
            else
            {
                num[1] = 4;
                ans--;
            }
            while (ans-- > 0)
                Mul_n_num(num, 3);
        }
        Print(num, len);
    }
    
    int main()
    {
        int n;
        cin >> n;
        Dis_int(n);
        
        system("pause");
        return 0;
    }
    
  • 1
    @ 2019-08-24 17:35:17

    我的快速幂居然每个点都是16ms,好慢。

    def quickm(x):
        ans=1
        base=3
        while(x>0):
            if(x&1==1):
                ans*=base
            base*=base
            x=x>>1
        return ans
    
    n=int(input())
    a=int(n/3)
    b=n%3
    if(b==1 and a>0):
        a-=1
        b=4
    if(b==0):
        print(quickm(a))
    else:
        print(quickm(a) * b)
    
  • 1
    @ 2017-08-09 12:12:47
    
    var m:longint;
    n:string;
    procedure getdata;
    begin
    readln(m);
    end;
    procedure multiply(n:integer;var s:string);
    var a:array[1..500] of integer;
    i,leng:longint;
    begin
    leng:=length(s);
    fillchar(a,sizeof(a),0);
    for i:=1 to length(s) do
    a[length(s)-i+1]:=ord(s[i])-ord('0');
    for i:=1 to length(s) do
    a[i]:=a[i]*n;
    for i:=1 to length(s) do
    if a[i]>=10 then
    begin
    a[i+1]:=a[i+1]+(a[i] div 10);
    a[i]:=a[i] mod 10;
    end;
    s:='';
    if a[leng+1]>0 then
    for i:=leng+1 downto 1 do
    s:=s+chr(a[i]+ord('0'))
    else
    for i:=leng downto 1 do
    s:=s+chr(a[i]+ord('0'));
    end;
    procedure output;
    begin
    writeln(n);
    end;
    function judge(s:longint):longint;
    begin
    if (s=1)or(s=2)or(s=3) then
    judge:=s-1
    else begin
    judge:=(s mod 3)+3;
    end;
    end;
    procedure calc(s:longint;var n:string);
    var i:longint;
    begin
    n:='1';
    case judge(s) of
    0:n:='1';
    1:n:='2';
    2:n:='3';
    3:begin
    for i:=1 to (s div 3) do
    multiply(3,n);
    end;
    4:begin
    for i:=1 to ((s div 3)-1) do
    multiply(3,n);
    for i:=1 to 2 do
    multiply(2,n);
    end;
    5:begin
    for i:=1 to (s div 3) do
    multiply(3,n);
    multiply(2,n);
    end;
    end;
    end;
    begin
    getdata;
    calc(m,n);
    output;
    end.
    
    
  • 1
    @ 2016-02-17 20:08:34

    n = int(input())
    k = n // 3
    w = n - 3*k
    if w == 1:
    if k>=1:
    print((3**(k-1))*4)
    else:
    print(1)
    elif w == 2:
    print((3**k)*2)
    else:
    print(3**k)
    这python太额心了

  • 1
    @ 2015-12-03 00:18:44

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>

    using namespace std;

    int main()
    {
    int n,a,b,c[4],x[4],m[510],s=0;
    cin >>n;

    c[1]=n;
    c[2]=n-2;
    c[3]=n-4;
    for (int i=1;i<=3;++i)
    if (c[i] % 3 == 0)
    {
    a=i-1;
    b=c[i]/3;
    }

    x[0]=1;
    for (int i=1;i<=a;++i)
    x[i]=x[i-1]*2;
    m[0]=1;
    for (int i=1;i<=b;++i)
    m[i]=m[i-1]*3;
    s=x[a]*m[b];
    cout << s <<endl;
    return 0;
    }

    • @ 2015-12-12 16:21:54

      打得不错

  • 0
    @ 2021-02-18 07:27:58

    尽量多取3,但是当遇到剩下一个1时改变策略,少一个3多两个2;没有多了解数学,但是如果局限在2和3,那么显然
    3 * 3 > 2 * 2 * 2,所以对于n > 6,取3好于取2,不停重复这个过程直到边界条件。我用了快速幂&高精度(最大可以到3^500),太久没写代码+本来就菜,写的既不美观也不清楚。。。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <iostream>
    
    using namespace std;
    
    const int MAXN = 500 + 10;
    
    struct BigInt {
        int length;
        int digits[MAXN];   // maximum 3^(1500/3) << 10^500
        BigInt() { length = 1; for (int i = 0; i <= 500; i++) digits[i] = 0; }
        
        BigInt(long long x) {
            length = 0; for (int i = 0; i <= 500; i++) digits[i] = 0;
            while (x) { 
                digits[++length] = x % 10;
                x /= 10;
            }
        }
    
        int& operator[](int x) {
            return digits[x];
        }
    
        BigInt operator*(BigInt x) {
            BigInt res;
            for (int i = 1; i <= length; i++) {
                for (int j = 1; j <= x.length; j++) {
                    res[i + j - 1] += digits[i] * x[j];
                }
            }
            int l = length + x.length - 1;
            for (int i = 1; i <= l; i++) {
                res[i + 1] += res[i] / 10;
                res[i] %= 10;
            }
            res.length = (res[l + 1] ? l + 1 : l);
            return res;
        }
    
        void operator *=(BigInt x) {
            BigInt res = x * (*this);
            for (int i = 1; i <= res.length; i++) {
                digits[i] = res[i];
            }
            length = res.length;
        }
    
        void output() {
            for (int i = length; i >= 1; i--) { cout << digits[i]; }
            cout << endl;
        }
    
    } num(1);
    
    void pow3(int cnt) {
        BigInt x(3);
        while(cnt) {
            if (cnt & 1) {
                num *= x;
            }
            cnt >>= 1; x *= x;
        }
    }
    
    void pow2(int cnt) {
        BigInt x;
        if (cnt == 1) { 
            x[1] = 2;
            num *= x;
        }
        else if (cnt == 2) {
            x[1] = 4;
            num *= x;
        }
    }
    
    int main() {
        int n;
        cin >> n;
        if (n > 4) {
            int num_three = n / 3;
            int num_two = 0;
            n %= 3;
            if (n == 1) { num_two = 2; num_three -= 1; }
            else if (n == 2) { num_two += 1; }
            pow3(num_three);
            pow2(num_two);
            num.output();
        } else {
            cout << n << endl;
        }
        return 0;
    }
    
  • 0
    @ 2017-11-27 15:51:55

    其实此题可以用DP做
    dp(i)表示用i所能达到的最大乘积
    转移方程dp(i)=dp(k) * dp(i-k)
    但是带着高精的DP贼恶心

  • 0
    @ 2017-01-08 16:15:09

    #include<stdio.h>
    #define q 10001
    int aa[q];
    int main()
    {
    aa[1]=1;
    int a,i,b=0,s=1;
    scanf("%d",&a);
    b=a/3;
    if(a>4)
    {
    if(a-3*b==1)
    {
    b-=1;
    aa[1]=4;
    }
    if(a-3*b==2)
    {
    aa[1]=2;
    }
    for(int j=1;j<=10001;j++)
    {
    int t=0,c=3;
    for(i=1;i<=s;i++)
    {

    aa[i]=aa[i]*c+t;
    t=aa[i]/10;
    aa[i]=aa[i]%10;
    }
    while(t>0)
    {
    aa[s+1]=t%10;
    s++;
    t/=10;
    }
    while(aa[s]==0)
    {
    s--;
    }
    b--;
    if(b<=0) break;
    }
    for(i=s;i>=1;i--)
    {
    printf("%d",aa[i]);
    }
    }
    else printf("%d",a);
    return 0;
    }

  • 0
    @ 2016-08-09 23:03:10
    #include <iostream>
    #include <cstring>
    #include <string>
    using namespace std;
    class bign 
    {
    private:
    
       int num[500], len;
    
    public:
    
       bign()
       {
           memset(num, 0, sizeof(num));
           len = 1;
       }
    
       bign(int x)
       {
           *this = x;
       }
    
       bign operator = (int x)
       {
           if (x)
               len = 0;
    
           while (x > 0)
           {
               num[len++] = x % 10;
               x /= 10;
           }
    
           return *this;
       }
    
       bign operator = (const bign &b)
       {
           memcpy(this, &b, sizeof(b));
           return *this;
       }
    
       bign operator * (const bign &b) const
       {
           bign c;
           
           c.len = len + b.len;
           
           for (int i = 0; i < len; i++)
               for (int j = 0; j < b.len; j++)
                   c.num[i+j] += num[i] * b.num[j];
    
           for (int i = 0; i < c.len; i++)
           {
               c.num[i+1] += c.num[i] / 10;
               c.num[i] %= 10;
           }
           for (int i = c.len - 1; i > 0; i--)
               if (c.num[i] == 0)
                   c.len--;
               else
                   break;
    
           return c;
       }
    
       bign& operator *= (const bign &b)
       {
           *this = *this * b;
           return *this;
       }
    
       string str() const
       {
           string s;
    
           for (int i = len - 1; i >= 0; i--)
               s = s + char(num[i] + '0');
    
           return s;
       }
    };
    ostream& operator << (ostream &out, bign &b)
    {
       return out << b.str();
    }
    
    int main()
    {
       int n;
       cin >> n;
       bign m = 1;
       int i;
       for (i = n; i > 4; i -= 3)
           m *= 3;
       m *= i;
       cout << m;
       return 0;
    }```
    直接套以前预备的高精度模板,懒得一句一句写高精度的程序了,当年入门时痛苦的回忆
    75ms应该不慢吧。。
    
    • @ 2017-01-04 00:21:50

      dalao求解

         for (i = n; i > 4; i -= 3)
             m *= 3;
         m *= i;
      

      这一段的缘由。。。。

  • 0
    @ 2016-07-28 21:28:47

    为了让代码可读性更高,我再发一遍:
    ···
    var
    r:array[1..1000]of longint;
    num,n,i,len,j:longint;
    begin
    readln(n);
    len:=1;
    case n of
    1,2:writeln(n);
    else begin
    case n mod 3 of
    0:begin
    num:=n div 3;
    r[1]:=1;
    end;
    1:begin
    num:=n div 3-1;
    r[1]:=4;
    end;
    2:begin
    num:=n div 3;
    r[1]:=2;
    end;
    end;
    for i:=1 to num do
    begin
    for j:=1 to len do r[j]:=r[j]*3;
    for j:=1 to len do
    if r[j]>=10 then
    begin
    inc(r[j+1],r[j] div 10);
    r[j]:=r[j] mod 10;
    end;
    if r[len+1]>0 then inc(len);
    end;
    for i:=len downto 1 do write(r[i]);
    writeln;
    end;
    end;
    end.
    ```

    • @ 2016-07-28 21:30:56

      必须说明,我是刚刚注册vijos账号的,对发表题解还不太会,请多加原谅。

    • @ 2016-08-01 12:24:45

      真棒!

  • 0
    @ 2016-07-28 21:27:21

    var
    r:array[1..1000]of longint;
    num,n,i,len,j:longint;
    begin
    readln(n);
    len:=1;
    case n of
    1:writeln(1);
    2:writeln(2);
    else begin
    case n mod 3 of
    0:begin
    num:=n div 3;
    r[1]:=1;
    end;
    1:begin
    num:=n div 3-1;
    r[1]:=4;
    end;
    2:begin
    num:=n div 3;
    r[1]:=2;
    end;
    end;
    for i:=1 to num do
    begin
    for j:=1 to len do r[j]:=r[j]*3;
    for j:=1 to len do
    if r[j]>=10 then
    begin
    inc(r[j+1],r[j] div 10);
    r[j]:=r[j] mod 10;
    end;
    if r[len+1]>0 then inc(len);
    end;
    for i:=len downto 1 do write(r[i]);
    writeln;
    end;
    end;
    end.
    这题很简单,要用高精度乘法,否则可能会会算术上溢错误。

  • 0
    @ 2016-03-20 15:08:51

    var
    a:array [0..1000] of longint;
    n,t,l,i:longint;
    procedure dd(x:longint);
    var i:longint;
    begin
    for i:=1 to l do a[i]:=a[i]*x;
    for i:=1 to l do begin inc(a[i+1],a[i] div 10); a[i]:=a[i] mod 10; end;
    if (a[l+1]<>0) then inc(l);
    end;
    begin
    readln(n);
    if (n<4) then begin writeln(n); exit; end;
    t:=n div 3; l:=1; a[1]:=1;
    if (n mod 3=1) then dec(t);
    for i:=1 to t do dd(3);
    if (n mod 3=1) then dd(4);
    if (n mod 3=2) then dd(2);
    for i:=l downto 1 do write(a[i]);
    writeln;
    end.

  • 0
    @ 2015-09-04 18:28:37

    #include <iostream>
    #include <cstdio>
    using namespace std;
    const int MAXN = 10000 + 5;
    int a[MAXN],n,len;

    void mul(int);
    void dfs(int);
    int main()
    {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    a[1]=1;
    scanf("%d",&n);
    dfs(n);
    len=1000;
    while(a[len]==0)
    len--;

    for (int i = len;i>=1;i--)
    {
    printf("%d",a[i]);
    }
    printf("\n");
    return 0;
    }
    void mul(int k)
    {
    const int BASE = 10;
    int enter=0;
    for(int i=1;i<=1000;i++)
    {
    a[i]=a[i]*k+enter;
    enter=a[i]/BASE;
    a[i]%=BASE;
    }

    }
    void dfs(int x)
    {
    switch(x)
    {
    case 1:
    return;
    case 2:
    mul(2);
    return;
    case 3:
    mul(3);
    return;
    case 4:
    mul(4);
    return;
    default:
    mul(3);
    dfs(x-3);
    }
    }

  • 0
    @ 2015-09-01 21:32:15

    P1033整数分解(版本2)Accepted
    记录信息
    评测状态 Accepted
    题目 P1033 整数分解(版本2)
    递交时间 2015-09-01 21:31:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 312 ms
    消耗内存 524 KiB
    评测时间 2015-09-01 21:31:27
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #1: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #2: Accepted, time = 15 ms, mem = 516 KiB, score = 2
    测试数据 #3: Accepted, time = 23 ms, mem = 520 KiB, score = 2
    测试数据 #4: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #5: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #6: Accepted, time = 1 ms, mem = 516 KiB, score = 2
    测试数据 #7: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #8: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #9: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #10: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #11: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #12: Accepted, time = 3 ms, mem = 520 KiB, score = 2
    测试数据 #13: Accepted, time = 21 ms, mem = 520 KiB, score = 2
    测试数据 #14: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #15: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #16: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #17: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #18: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #19: Accepted, time = 1 ms, mem = 516 KiB, score = 2
    测试数据 #20: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #21: Accepted, time = 0 ms, mem = 524 KiB, score = 2
    测试数据 #22: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #23: Accepted, time = 15 ms, mem = 516 KiB, score = 2
    测试数据 #24: Accepted, time = 15 ms, mem = 516 KiB, score = 2
    测试数据 #25: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #26: Accepted, time = 1 ms, mem = 516 KiB, score = 2
    测试数据 #27: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #28: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #29: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #30: Accepted, time = 2 ms, mem = 516 KiB, score = 2
    测试数据 #31: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #32: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #33: Accepted, time = 15 ms, mem = 516 KiB, score = 2
    测试数据 #34: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #35: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #36: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #37: Accepted, time = 1 ms, mem = 520 KiB, score = 2
    测试数据 #38: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #39: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #40: Accepted, time = 15 ms, mem = 516 KiB, score = 2
    测试数据 #41: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #42: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #43: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #44: Accepted, time = 0 ms, mem = 520 KiB, score = 2
    测试数据 #45: Accepted, time = 1 ms, mem = 520 KiB, score = 2
    测试数据 #46: Accepted, time = 0 ms, mem = 516 KiB, score = 2
    测试数据 #47: Accepted, time = 1 ms, mem = 520 KiB, score = 2
    测试数据 #48: Accepted, time = 15 ms, mem = 520 KiB, score = 2
    测试数据 #49: Accepted, time = 47 ms, mem = 516 KiB, score = 2
    Accepted, time = 312 ms, mem = 524 KiB, score = 100
    代码
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int ans[1001];
    int num[3];
    int main()
    {
    int n;
    scanf("%d",&n);
    if(n==1){
    printf("1");
    return 0;
    }
    if(n==2){
    printf("2");
    return 0;
    }
    num[2]=1;
    for(int i=3;i<n;i++)
    {
    if(num[1]==0)
    {
    num[2]-=1;
    num[1]+=2;
    }
    else
    {
    num[1]-=1;
    num[2]+=1;
    }
    }
    ans[1]=1;
    ans[0]=1;
    for(int i=1;i<=num[2];i++)
    {
    int j,in=0;
    for(j=1;j<=ans[0]||in;j++)
    {
    int now=ans[j]*3+in;
    ans[j]=now%10;
    in=now/10;
    }
    if(j-1>ans[0])
    ans[0]=j-1;
    }
    for(int i=1;i<=num[1];i++)
    {
    int j,in=0;
    for(j=1;j<=ans[0]||in;j++)
    {
    int now=ans[j]*2+in;
    ans[j]=now%10;
    in=now/10;
    }
    if(j-1>ans[0])
    ans[0]=j-1;
    }
    for(int i=ans[0];i>=1;i--)
    printf("%d",ans[i]);
    }

  • 0
    @ 2015-03-26 15:11:56

    #include<iostream>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<time.h>
    #include<stdlib.h>
    using namespace std;

    int a[1005];
    void mul(int k){
    int i;
    int enter = 0;
    for (i = 0; i < 1000; i++){
    a[i] *= k;
    a[i] += enter;
    enter = a[i] / 10;
    a[i] %= 10;
    }
    }
    int main(){
    int n;
    cin >> n;
    int t = n % 3;
    int k = n / 3;
    k--;
    a[0] = 1;
    while (k--){
    mul(3);
    }
    if (t == 0)mul(3);
    if (t == 1)mul(4);
    if (t == 2)mul(6);
    int i;
    for (i = 1000; !a[i]; i--);
    while (i >= 0)cout << a[i--];
    return 0;
    }

  • 0
    @ 2014-12-19 20:48:35

    var a,b,c:array[1..100000] of integer;
    i,j,m,n,x,l1,l2,jw,p,s:longint;
    begin
    readln(m);
    if m=1 then
    begin
    writeln('1');
    halt;
    end;
    case m mod 3 of
    0:begin
    x:=m div 3;
    p:=0;
    end;
    1:begin
    x:=m div 3-1;
    p:=2;
    end;
    2:begin
    x:=m div 3;
    p:=1;
    end;
    end;
    a[1]:=1;
    l1:=1;
    for j:=1 to x do
    begin
    for i:=1 to l1 do
    begin
    a[i]:=a[i]*3+jw;
    jw:=a[i] div 10;
    a[i]:=a[i] mod 10;
    end;
    while jw<>0 do
    begin
    l1:=l1+1;
    a[l1]:=jw mod 10;
    jw:=jw div 10;
    end;
    end;
    for i:=1 to p do
    begin
    for j:=1 to l1 do
    begin
    a[j]:=a[j]*2+jw;
    jw:=a[j] div 10;
    a[j]:=a[j] mod 10;
    end;
    while jw<>0 do
    begin
    l1:=l1+1;
    a[l1]:=jw mod 10;
    jw:=jw div 10;
    end;
    end;
    for i:=l1 downto 1 do
    write(a[i]);
    end.

  • 0
    @ 2014-12-17 15:42:59

    VAR
    N,M,I,J,K,L:LONGINT;
    A:ARRAY[1..1000] OF LONGINT;
    PROCEDURE ASD(K:LONGINT);
    VAR
    I,S:LONGINT;
    BEGIN
    S:=0;
    FOR I:=1 TO M DO
    BEGIN
    A[I]:=A[I]*K+S;
    S:=A[I] DIV 10;
    A[I]:=A[I] MOD 10;
    END;
    IF S>0 THEN BEGIN INC(M);
    A[M]:=S; END;
    END;
    BEGIN
    READLN(N);
    M:=1;
    A[1]:=1;
    IF N=1 THEN BEGIN WRITELN(1);HALT END;
    IF N MOD 3=0 THEN
    BEGIN
    FOR I:=1 TO N DIV 3 DO
    ASD(3);
    END
    ELSE IF N MOD 3=1 THEN
    BEGIN
    FOR I:=1 TO N DIV 3-1 DO
    ASD(3);
    ASD(4);
    END
    ELSE IF N MOD 3=2 THEN
    BEGIN
    FOR I:=1 TO N DIV 3 DO
    ASD(3);
    ASD(2);
    END;
    FOR I:=M DOWNTO 1 DO WRITE(A[I]);
    END.

  • 0
    @ 2014-12-17 12:37:58

    Pascal CODE:
    var a,b,c:array[1..100000] of integer;

    i,j,m,n,x,l1,l2,jw,p,s:longint;

    begin

    readln(m);

    if m=1 then

    begin

    writeln('1');

    halt;

    end;

    case m mod 3 of

    0:begin

    x:=m div 3;

    p:=0;

    end;

    1:begin

    x:=m div 3-1;

    p:=2;

    end;

    2:begin

    x:=m div 3;

    p:=1;

    end;

    end;

    a[1]:=1;

    l1:=1;

    for j:=1 to x do

    begin

    for i:=1 to l1 do

    begin

    a[i]:=a[i]*3+jw;

    jw:=a[i] div 10;

    a[i]:=a[i] mod 10;

    end;

    while jw<>0 do

    begin

    l1:=l1+1;

    a[l1]:=jw mod 10;

    jw:=jw div 10;

    end;

    end;

    for i:=1 to p do

    begin

    for j:=1 to l1 do

    begin

    a[j]:=a[j]*2+jw;

    jw:=a[j] div 10;

    a[j]:=a[j] mod 10;

    end;

    while jw<>0 do

    begin

    l1:=l1+1;

    a[l1]:=jw mod 10;

    jw:=jw div 10;

    end;

    end;

    for i:=l1 downto 1 do

    write(a[i]);

    end.

  • 0
    @ 2014-08-24 15:22:08

    n=int(raw_input())
    a=[]
    a.append(1)
    a.append(2)
    a.append(3)
    for i in range(3,n):a.append(max(a[i-2]*2,a[i-3]*3))
    print a[n-1]

  • 0
    @ 2014-07-06 22:13:41

    27 lines compiled, 0.1 sec , 28320 bytes code, 1628 bytes data

    测试数据 #0: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #1: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #2: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #3: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #4: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #5: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #6: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #7: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    测试数据 #8: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #9: Accepted, time = 15 ms, mem = 736 KiB, score = 2

    测试数据 #10: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #11: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #12: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #13: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #14: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #15: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #16: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #17: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #18: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #19: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #20: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #21: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    测试数据 #22: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #23: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #24: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #25: Accepted, time = 0 ms, mem = 736 KiB, score = 2

    测试数据 #26: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #27: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    测试数据 #28: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #29: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #30: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #31: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #32: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #33: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #34: Accepted, time = 0 ms, mem = 736 KiB, score = 2

    测试数据 #35: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    测试数据 #36: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #37: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #38: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #39: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #40: Accepted, time = 15 ms, mem = 744 KiB, score = 2

    测试数据 #41: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #42: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    测试数据 #43: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #44: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #45: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #46: Accepted, time = 15 ms, mem = 740 KiB, score = 2

    测试数据 #47: Accepted, time = 0 ms, mem = 740 KiB, score = 2

    测试数据 #48: Accepted, time = 7 ms, mem = 740 KiB, score = 2

    测试数据 #49: Accepted, time = 0 ms, mem = 744 KiB, score = 2

    Accepted, time = 217 ms, mem = 744 KiB, score = 100
    没有秒杀

信息

ID
1033
难度
5
分类
其他 | 数学 点击显示
标签
(无)
递交数
3640
已通过
1179
通过率
32%
被复制
5
上传者