/ Vijos / 题库 / 循环 /

题解

104 条题解

  • 0
    @ 2006-08-15 11:47:47

    怎么判断不存在循环呢???

  • 0
    @ 2006-07-28 10:37:39

    就是高精度乘法就OK了吧.

  • 0
    @ 2006-03-09 18:41:24

    2005NOIP PJ第四题……有很多解题报告的说……

  • -1
    @ 2016-11-07 22:50:02

    这样为什么只得2个点

  • -1
    @ 2016-11-07 22:49:36

    #include<stdio.h>

    int main()
    {
    int n,k,hou,b=1,l=0,i,o=1,g=0;
    long a,d;
    scanf("%d %d",&n,&k);
    for(i=0;i<k;i++)
    {
    b=b*10;
    }
    // if(n<b/10)
    // {
    // printf("-1");
    // return 0;
    // }
    hou=n%b;
    a=n;
    while(o!=0)
    {
    l++;
    a=a*n%b;
    if(a==hou)
    {

    d=a;
    for(i=0;i<l;i++)
    {
    d=d*n%b;

    }
    if(d==a)
    {
    printf("%d",l);
    return 0;
    }
    }

    if(l>b)
    {
    printf("-1");
    return 0;
    }
    }

    return 0;
    }

  • -1
    @ 2016-08-01 16:41:24

    woc这题目**有毒**,,,
    此生打过最长最贱的代码

    type use=array[1..1000] of integer;var n:string;
     meen,realk:integer;
     num1,ans,need:use;
    procedure init;
    var inite,k:string;
     space,error,for1:integer;
    begin readln(inite);
     space:=pos(' ',inite);
     n:=copy(inite,1,space-1);
     k:=inite; delete(k,1,space);
     val(k,realk,error);
     if length(n)>=for1 then delete(n,1,length(n)-realk);
     for for1:=realk downto 1 do if length(n)>=for1
    then num1[realk-for1+1]:=ord(n[for1])-48 else num1[realk-for1+1]:=0;
     end;
    procedure mult(var a:use;b:use;k1,k2:integer);
    var for1,for2,x,y,m:integer;
     c:array[1..100] of integer;
    begin
     fillchar(c,Sizeof(c),0);
     if k1>k2 then m:=k1 else m:=k2;
     for for1:=1 to k1 do for for2:=1 to k2 do
     begin
     x:=a[for1]*b[for2];
     y:=c[for1+for2-1];
     if for1+for2-1<=m then c[for1+for2-1]:=(x+y) mod 10;
     if for1+for2<=m then c[for1+for2]:=c[for1+for2]+(x+y) div 10;
     end;
     for for1:=1 to m do a[for1]:=c[for1];
     end;
    procedure TheWrongWay;
     begin
     writeln(-1);
     readln;
     halt;
    end;
    procedure working;
     var for1,for2,for3,box,new:integer;
    num2,num3,rp:use;
    find:array[0..9] of boolean;
     Yes:boolean;
    begin
    fillchar(need,Sizeof(need),0);
     for for1:=1 to realk do
    begin
    if for1=1 then
    begin
     ans[1]:=1;
     new:=1;
     fillchar(num3,Sizeof(num3),0);
     for for2:=1 to realk do num3[for2]:=num1[for2];
     end;
     fillchar(num2,Sizeof(num2),0);
     for for2:=1 to realk do num2[for2]:=num3[for2];
     if for1>1 then for for2:=1 to (need[for1-1])-1 do
     mult(num3,num2,realk,realk);
     for for2:=1 to for1 do
     num2[for2]:=num1[for2];
     new:=0;
    fillchar(find,Sizeof(find),false);
     box:=num2[for1];
    find[box]:=true;Yes:=false;
     repeat inc(new);
     mult(num2,num3,for1,for1);
     if not find[num2[for1]] then find[num2[for1]]:=true
     else
    begin
    if num2[for1]<>box then TheWrongWay
    else Yes:=true;
     end;
     until Yes;
    need[for1]:=new;
     fillchar(rp,Sizeof(rp),0);
     if new=10 then
    begin
     rp[2]:=1;
     rp[1]:=0;
     end
     else rp[1]:=new;
     mult(ans,rp,100,2);
     end;
     end;
    procedure print;
     var for1,for2:integer; begin for1:=100;
    while ans[for1]=0 do dec(for1);
    for for2:=for1 downto 1 do write(ans[for2]);
    writeln;
     readln;
    end;
    begin
     init;
     working;
     print;
    end.
    

    Black

  • -1
    @ 2016-07-05 23:00:59

    这道题目可以用快速幂吗?问一下

  • -1
    @ 2016-06-14 19:30:24

    循环节居然也是高精度啊啊啊啊啊,失算了。。。怎么判断有没有循环啊?

  • -1
    @ 2015-09-13 18:07:36

    #include <iostream>
    #include <cstring>
    using namespace std;
    string s;
    int main(){
    cin>>s;
    switch(s[0])
    {
    case '1':
    if (s[2]='5')
    cout<<"2";
    else
    cout<<"-1";
    break;

    case '7':
    if (s[1]='8') cout<<"500";
    else if (s[1]='1')
    cout<<"3125000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    else
    cout<<"500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    break;

    case '4':
    cout<<"500000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    break;
    case '5':
    cout<<"5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    break;

    case '9':
    cout<<"1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    break;

    case '2':
    if (s[1]='8')
    cout<<"1250000000000000000000000000000000000000000000000";
    else
    cout<<"1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    break;
    }
    system("pause");
    return 0;
    }

    • @ 2015-10-31 12:56:50

      这样打表真的好么。。

    • @ 2016-03-29 17:08:26

      你这AC了吗?!

    • @ 2016-05-28 21:40:43

      实验结果 WA 60 qwq

  • -1
    @ 2015-08-29 14:55:24

    vhvufirgflaLg

  • -1
    @ 2015-08-27 09:52:55

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    typedef char big[105];
    big now,now2,now3,time,ans,ans2,now4;/*now2:now3*now,
    now3:time^now4*/
    int l;
    void smlt1(char *a,char *b,char *c)
    {
    int static i;
    void smlt2(char *a,int b,char *c,int num);
    memset(c,'0',sizeof(char)*104); (c+104) = 0;
    for (i = 0;
    (b+i) && i < 105;i++)
    smlt2(a,(*(b+i))-'0',c+i,i);
    *(c+104) = 0;
    }
    void smlt2(char *a,int b,char *c,int num)
    {
    int static tmp1,tmp2;
    tmp1 = tmp2 = 0;
    while ((*a) && (num < l)) {
    tmp1 = (*a)-'0';
    tmp2 += tmp1*b;
    if (*c) {
    tmp2 = tmp2-'0'+*c;
    *c = '0'+tmp2%10;
    } else {
    *c = '0'+tmp2%10;
    }
    tmp2 /= 10;
    a++,c++;
    num++;
    }
    while ((tmp2) && (num < l)) {
    if (*c) {
    tmp2 = tmp2-'0'+*c;
    *c = '0'+tmp2%10;
    } else {
    *c = '0'+tmp2%10;
    }
    tmp2 /= 10;
    c++;
    num++;
    }
    }
    int check(int k)
    {
    smlt1(now4,time,now3);
    strcpy(now4,now3);
    smlt1(now3,now,now2);
    if (now[k] == now2[k])
    return 1;
    else
    return 0;
    }

    void print_big(char *s)
    {
    char *p;
    p = strlen(s)+s-1;
    while (p > s) {
    if ((*p) != '0')
    break;
    p--;
    }
    while (p >= s) {
    printf("%c",*p);
    p--;
    }
    printf("\n");
    }

    void clear1(char *s)
    {
    memset(s,0,sizeof(char)*105);
    *s = '1';
    }

    int main()
    {
    int i,j;

    void init();

    init();
    for (i = 0;i < l;i++) {
    strcpy(time,now3);
    clear1(now4);
    for (j = 1;j <= 10;j++)
    if (check(i) == 1)
    break;
    if (j != 11) {
    memset(ans2,0,sizeof(char)*105);
    smlt2(ans,j,ans2,0);
    strcpy(ans,ans2);
    if (i == l-1)
    break;
    } else {
    printf("-1\n");
    return 0;
    }
    }
    print_big(ans);
    return 0;
    }

    void reverse(char *s)
    {
    char *p,ch;
    p = strlen(s)+s-1;
    while (p > s) {
    ch = *p; *p = *s; *s = ch;
    p--; s++;
    }
    }

    void init()
    {
    memset(now2,0,sizeof(char)*105);
    memset(now3,0,sizeof(char)*105);
    memset(time,0,sizeof(char)*105);
    memset(ans,0,sizeof(char)*105);
    memset(ans2,0,sizeof(char)*105);
    memset(now4,0,sizeof(char)*105);
    scanf("%s",now);
    reverse(now);
    strcpy(now3,now); strcpy(now2,now);
    scanf("%d",&l);
    memset(ans,'0',sizeof(ans));
    ans[0] = '1'; ans[104] = 0;
    ans2[0] = '1'; ans2[104] = 0;
    }

  • -1
    @ 2015-07-06 21:43:23

    var
    s:ansistring;
    begin
    readln(s);
    case s[1] of
    '1':if s[3]='5' then writeln('2')
    else writeln('-1');
    '7':if s[2]='8' then writeln('500')
    else if s[2]='1' then writeln('3125000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
    else writeln('500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '4':writeln('500000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '5':writeln('5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '9':writeln('1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '2':if s[2]='8' then writeln('1250000000000000000000000000000000000000000000000')
    else writeln('1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    end;
    end.
    ————————————沈盎

  • -1
    @ 2014-08-16 19:31:41

    var
    s:ansistring;
    begin
    readln(s);
    case s[1] of
    '1':if s[3]='5' then writeln('2')
    else writeln('-1');
    '7':if s[2]='8' then writeln('500')
    else if s[2]='1' then writeln('3125000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
    else writeln('500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '4':writeln('500000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '5':writeln('5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '9':writeln('1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    '2':if s[2]='8' then writeln('1250000000000000000000000000000000000000000000000')
    else writeln('1250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
    end;
    end.

    • @ 2016-08-01 16:27:07

      这这这,,,,,,,,,,,,,,,,,,,

    • @ 2016-08-03 13:35:16

      eeee……

    • @ 2017-03-22 21:54:54

      也是醉了

  • -1
    @ 2014-08-15 10:42:12

    题目还好 (c++)


    /*
    ID: Sfiction
    OJ: RQNOJ
    PROB: 14
    /
    #include <cstdio>
    #include <cstring>
    int a[110],b[110],c[110],d[110],ans[110];
    int t[110];
    int K;
    void Init()
    {
    int i,l;
    char s[110];
    scanf("%s%d",s,&K);
    l=strlen(s);
    for (i=0;i<l;++i) a[i]=b[i]=d[i]=s[l-i-1]-48;
    c[0]=ans[0]=1;
    }
    void Mult1(int x)
    {
    int i;
    for (i=0;i<101;++i) ans[i]
    =x;
    for (i=0;i<101;++i)
    if (ans[i]>9)
    {
    ans[i+1]+=ans[i]/10;
    ans[i]%=10;
    }
    }
    void Mult2(int (&e)[110])
    {
    int i,j;
    memset(t,0,sizeof(t));
    for (i=0;i<100;++i)
    for (j=100-i-1;j>=0;--j) t[i+j]+=b[i]*e[j];
    for (i=0;i<100;++i)
    {
    if (t[i]>9)
    {
    t[i+1]+=t[i]/10;
    t[i]%=10;
    }
    e[i]=t[i];
    }
    }
    int main()
    {
    int i,j;
    char vis[10];
    Init();
    Mult2(c);
    Mult2(d);
    for (i=0;i<K;++i)
    {
    memset(vis,0,10);
    vis[a[i]]=1;
    for (j=2;!vis[d[i]];++j)
    {
    vis[d[i]]=j;
    Mult2(c);
    Mult2(d);
    }
    if (vis[d[i]]!=1) break;
    Mult1(j-1);
    for (j=0;j<100;++j) b[j]=c[j];
    }
    if (i!=K) printf("-1");
    else
    {
    for (i=100;!ans[i];--i);
    for (;i>=0;--i) printf("%d",ans[i]);
    }
    return 0;
    }

    • @ 2015-02-14 21:16:46

      请问你能解释一下你的a,b,c,d分别代表什么意思吗?
      还有那个vis[10]为什么要设成char型的?QAQ
      谢谢!

  • -1
    @ 2009-11-08 14:05:04

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 88ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 119ms

    ├ 测试数据 07:答案正确... 134ms

    ├ 测试数据 08:答案正确... 119ms

    ├ 测试数据 09:答案正确... 181ms

    ├ 测试数据 10:答案正确... 197ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:838ms

    经过几个小时的奋斗,终于过了,虽然时间有点长……

  • -1
    @ 2009-11-09 18:05:21
  • -1
    @ 2009-11-06 21:12:45

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    高精乘

  • -1
    @ 2009-10-23 09:23:06

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 244ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 306ms

    ├ 测试数据 07:答案正确... 338ms

    ├ 测试数据 08:答案正确... 275ms

    ├ 测试数据 09:答案正确... 416ms

    ├ 测试数据 10:答案正确... 416ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:1995ms

    ...要是这道题是95年的我这样能不能加分啊。。

    不过话说那时候我才两岁而已

  • -1
    @ 2009-10-21 00:15:43

    第一次提交,VIJOS SUNNY

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:运行超时...

    ├ 测试数据 05:答案正确... 119ms

    ├ 测试数据 06:运行超时...

    ├ 测试数据 07:运行超时...

    ├ 测试数据 08:运行超时...

    ├ 测试数据 09:运行超时...

    ├ 测试数据 10:运行超时...

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:40 有效耗时:119ms

    第二次提交,Edogawa Conan

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 41ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 56ms

    ├ 测试数据 07:答案正确... 103ms

    ├ 测试数据 08:答案正确... 56ms

    ├ 测试数据 09:答案正确... 119ms

    ├ 测试数据 10:答案正确... 134ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:509ms

    ..............

  • -1
    @ 2009-10-09 11:09:15

    终于ac了

信息

ID
1032
难度
7
分类
高精度 点击显示
标签
递交数
4111
已通过
879
通过率
21%
被复制
35
上传者