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;  
    } 
    
    
    
     
  • 相关阅读:
    Docker的使用
    Django常见问题
    Linux系统使用
    Nginx
    Redis
    MySQL基础、主从复制、优化
    Python常见的问题
    Python基础知识
    Vue的使用
    python监控tomcat日记文件
  • 原文地址:https://www.cnblogs.com/GoAhead/p/2682351.html
Copyright © 2011-2022 走看看