http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1044
代碼:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int x,y;
long long a,b,a_bit,b_bit,p,temp;
double anchor;
//freopen("1044_in.txt","r",stdin);
scanf("%d%d", &x, &y);
if(0 == x)
{
printf("0");
exit(0);
}
a = 1;
b_bit = 0;
p = 0;
anchor = 1;
temp = x;
while(temp/=10){anchor*=10,p++;};
anchor/=x;
while(b_bit<y)
{
a_bit = b_bit;
b = a;
p++;
anchor*=10;
a=anchor;
if(anchor - (int)anchor != 0.0) a++;
b_bit += (a-b)*p;
}
if(y == b_bit) printf("%lld\n",((a-1)%10)*(x%10)%10);
else
{
y-=a_bit;
if(y%p)
{
a=y/p+b;
b=p-y%p;
}
else
{
a=y/p+b-1;
b=0;
}
temp=x*a;
while(b--)
{
temp/=10;
}
printf("%d",temp%10);
}
return 0;
}
思路:
1、不能太暴力,會超時。
2、long long。