[P1980] 级数求和
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define lu unsigned long long
#define str(a,b) sprintf(a,"%llu",b)
int main(){
lu n,x,t,rk=0;
char*d;
scanf("%llu %llu",&n,&x);
lu cc(char a,lu b);
for(t=1;t<=n;t++){
rk+=cc(x+48,t);
//printf("t=%lu,rk(n)=%lu\n",t,cc(x+48,t));
}
printf("%llu",rk);
}
lu cc(char a,lu b){
char* tostr(lu a);
lu t=0,rk=0;
char*ttt=tostr(b);
for(t=0;t<=strlen(ttt);t++){
if(t[ttt]==a)
rk++;
}
free((void*)ttt);
return rk;
}
char* tostr(lu a){
char *ss=(char*)malloc(sizeof(char)*a);
str(ss,a);
return ss;
}
建议O2
本文来自博客园,作者:Ruptpsych,转载请注明原文链接:https://www.cnblogs.com/obj-a/p/13597777.html