P1033 求大牛分析。。

#include<iostream>
using namespace std;
typedef unsigned long long ull;
ull power(ull x, ull y);
int main()
{
ull n,m;
cin>>n;
if(n>4)
{
if(n%3==0)
m=power(3,n/3);
if(n%3==1)
m=power(3,(n-4)/3)*4;
if(n%3==2)
m=power(3,(n-2)/3)*2;

}
else if(n=4)m=4;
else if(n=3)m=2;
else if(n=2)m=1;
else if(n=1)m=0;
cout<<m;
return 0;
}

ull power(ull x,ull y)
{
if(x==0) return 0;
ull product=1;
if(y>=0)
while(y>0)
{
product*=x;
y--;

}
else
while(y<0)
{
product/=x;
y++;

}

return product;
}

一直只能过4个点。。。不知道为什么。。

4 条评论

  • @ 2015-04-20 21:20:32

    1500太大,不用高精度就爆了

  • @ 2014-02-01 11:05:31

    这个要高精度.n=1500最大时,最大是m=3^500,早就爆int64了

  • @ 2013-10-22 21:06:56

    用高精度
    2*3*.....*k 会超longlong(2+3+4+...+k=1500)

  • @ 2013-09-29 17:53:02

    通过一个数学定理,得:将这几个数分解成和e无限接近的数,相乘可取到最大值。所以尽量取3。
    program p1033;
    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

信息

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