题目链接: http://acm.pku.edu.cn/JudgeOnline/problem?id=3720 题目还是比较简单的,就是求1 - 100 之间的数的循环小数表示用了哪些数字#include "iostream" #include "cstdlib" #include "cstdio" #include "cstring" using namespace std; const int MaxN = 1010; bool use[MaxN]; int ans[MaxN]; int cnt[110][10]; int calc(int N){ memset(use, false,sizeof(use)); use[1] = true; int tmp = 10; int i = 0; while(!use[tmp]){ while(tmp < N){ if(use[tmp]) return i; use[tmp] = true; ans[i++] = 0; tmp *= 10; } if(use[tmp]) return i; use[tmp] = i; ans[i++] = tmp / N; tmp = tmp % N; if(use[tmp]) return i; if(tmp == 0) return i; tmp *= 10; } return i; } int main(){ for(int i = 2;i <=100; ++i){ int pos = calc(i); for(int j = 0;j < pos; ++j) ++cnt[i][ans[j]]; } int num,K; while(scanf("%d%d",&num,&K)==2){ int ret = 0; for(int i = 2;i <= num; ++i) ret += cnt[i][K]; printf("%d/n",ret); } return 0; }