程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> SGU111 大數開方 Evolution

SGU111 大數開方 Evolution

編輯:C++入門知識

Problem: You are given natural number X. Find such maximum integer number that it square is not greater than X.(X.length<1000)

解法:想用java水過但是跪了。上網查到了筆算開方,不過另一段短小的程序卻更神奇。完全不會= 。= 於是收錄在這裡了。

Solution: A small piece of code can solve it but I don't know why. _(:3」∠)_

#include 
#include 
#include 
using namespace std;
int l;
int work(int o,char *O,int I) {
    char c, *D=O ;
    if (o>0) {
        for (l=0;D[l];D[l++]-=10) {
            D[l++] -= 120;
            D[l] -= 110;
            while (!work(0,O,l)) D[l] += 20;
            putchar((D[l]+1032)/20);
        }
        putchar(10);
    }
    else {
        c = o+(D[I]+82)%10-(I>l/2)*(D[I-l+I]+72)/10-9;
        D[I] += I<0?0:!(o=work(c/10,O,I-1))*((c+999)%10-(D[I]+92)%10);
    }
    return o;
}
int main() {
    char s[1200];
    s[0]='0';
    scanf("%s",s+1);
    if (strlen(s)%2 == 1) work(2,s+1,0);
    else work(2,s,0);
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved