用打表的方法来做,蕴含着一种递推的思想。
#include <iostream> #include <cstdio> using namespace std; int n, res[1024]; const int MOD = 1e9 + 7; void init() { res[1] = res[2] = 1; for (int i = 3; i <= 1000; ++i) for (int j = 1; j < i; ++j) if ((i - 1) % j == 0) res[i] = (res[i] + res[j]) % MOD; } int main() { init(); int n, kase = 0; while (cin >> n) printf("Case %d: %d ", ++kase, res[n]); return 0; }