zoukankan      html  css  js  c++  java
  • N的M次方,N和M都是超级大数,的后六位求法

    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    void fun(const char *a,const char *b ,char *c)
    {
        
        int remainder=0;
        int length=strlen(a)>strlen(b)?strlen(a):strlen(b);
        int x=length;
        for (int i=strlen(a)-1,j=strlen(b)-1;i>=0||j>=0;i--,j--)
        {
            int x1,x2;
            if (i>=0) 
                x1=a[i]-'0';
            else
                x1=0;
            if (j>=0) 
                x2=b[j]-'0';
            else
                x2=0;
            div_t temp=div(x1+x2+remainder,10);
            remainder=temp.quot;
            c[length--]=temp.rem+'0';
            
        }    
        if(remainder!=0)
        {
            c[0]=remainder+'0';
            c[x+1]='\0';
        }
        else
        {
            for (int i=0;i<=x+1;i++)
            {
                c[i]=c[i+1];
            }
            c[x]='\0';
        }
    }
    void main()
    {
        
        char sum[100000]={"\0"};
        char temp1[100000]={'\0'};
        char temp2[100000]={'\0'};
        sum[0]='1';
        for (int i=1;i<=722;i++)
        {
            if (strlen(sum)>6)
            {
                strcpy(temp2,sum+strlen(sum)-6);
                strcpy(temp1,sum+strlen(sum)-6);
            }
            else
            {
                strcpy(temp2,sum);
                strcpy(temp1,sum);
            }
            
            for (int j=1;j<=14694;j++)
            {
                fun(temp1,temp2,sum);
                if (strlen(sum)>6)
                {
                    strcpy(temp1,sum+strlen(sum)-6);
                }
                else
                {
                    strcpy(temp1,sum);
                }
            }
            
        }
        
        cout<<sum<<endl;
        
    }

    #include<stdio.h>  
    int main()  
    {  
        int i,x,y,last= 1; /*变量last保存求X的Y次方过程中的部分乘积的后三位*/  
        printf("Input X and Y(X**Y):");  
        scanf("%d**%d",&x,&y);  
        for(i = 1;i <= y;i++) /*X自乘Y次*/  
            last = last * x % 1000; /*将last乘X后对1000取模,即求积的后三位*/  
        printf("The last 3 digits of %d**%d is:%d\n",x,y,last%1000); /*打印结果*/  
        return 0;  
    } 
    
    
    
     
  • 相关阅读:
    【源码剖析】HashMap1.7 详解
    友链
    P4747 [CERC2017]Intrinsic Interval
    Educational Codeforces Round 97 简要题解
    CF908D New Year and Arbitrary Arrangement(期望 dp)
    一个方便的自定义注解,管理实体类
    Leetcode 657 机器人能否回到原点
    Leetcode 695 岛屿的最大面积 二维平面DFS
    WebSocket 的简单用例
    俄罗斯方块JAVA
  • 原文地址:https://www.cnblogs.com/GoAhead/p/2682351.html
Copyright © 2011-2022 走看看