#44435: c++解題思路


zhen0718 (umirnco)

學校 : 不指定學校
編號 : 295257
來源 : [125.231.128.36]
最後登入時間 :
2024-12-05 00:06:09
a111. 12149 - Feynman -- UVa12149 | From: [125.231.128.36] | 發表日期 : 2024-12-05 00:24

很簡單,要不然壓縮程式碼,要不然體換 scanf 和 printf

 

第一種測試 

AC (1ms, 76KB)

main(){long long b;for(;~scanf("%lld",&b)&&b;)printf("%lld\n",b*(b+1)*(2*b+1)/6);}

 

第二種測試

AC (1ms, 40KB) 

用 getchar_unlocked  putchar_unlocked 替換 scanf 和 printf

inline long long read() {

    long long n = 0, c = getchar_unlocked();

    while (c < '0' || c > '9') c = getchar_unlocked();

    while (c >= '0' && c <= '9') n = n * 10 + (c - '0'), c = getchar_unlocked();

    return n;

}

 

inline void write(long long x) {

    if (x > 9) write(x / 10);

    putchar_unlocked(x % 10 + '0');

}

 

main() {

    long long b;

    while ((b = read()) && b) {

        write(b * (b + 1) * (2 * b + 1) / 6);

        putchar_unlocked('\n');

    }

}

 
ZeroJudge Forum