硬做就行,素数表要是懒不筛都行,只需要知道约数求和公式,这个请百度并且加强一下积性函数的理解。 #include <cstdio> int main( ) { int t, n, p, i, ans, s; scanf("%d", &t); while ( t-- ) { scanf("%d", &n); p = n; ans = 1; i = 2; while ( i * i <= p ) { if ( p % i == 0 ) { s = i; while ( p % i == 0 ) { p /= i; s *= i; } ans *= ( s - 1 ) / ( i - 1 ); } i++; } if ( p != 1 ) ans *= p + 1; printf("%d\n", ans - n); } return 0; }