Multiple
Time Limit: 2 Sec Memory Limit: 64 MBSubmissions: 140 Solved: 17
Description
Rocket323 loves math very much. One day, Rocket323 got a number string. He could choose some consecutive digits from the string to form a number.Rocket323 loves 64 very much, so he wanted to know how many ways can he
choose from the string so the number he got multiples of 64 ?
A number cannot have leading zeros. For example, 0, 64, 6464, 128 are numbers which multiple of 64 , but 12, 064, 00, 1234 are not.
Input
Multiple cases, in each test cases there is only one line consist a number string.
Length of the string is less than 3 * 10^5 .
Huge Input , scanf is recommended.
Output
Print the number of ways Rocket323 can choose some consecutive digits to form a number which multiples of 64.
Sample Input
64064
Sample Output
5
HINT
There are five substrings which multiples of 64.
[64]064
640[64]
64[0]64
[64064]
[640]64
Source
Problem Setter : Yang Xiao
题意:问输入一个字符串 其中连续字符串是64的倍数的个数 注意0开头的不算 如
[64]064
640[64]
64[0]64
[64064]
[640]64
括号内的为64的倍数
/*看了标程才搞懂了
首先要知道1000000 是64的倍数 所以 对于长度大于6的数字串 只要判断后6位是否能够被64整除即可
*/
#include<stdio.h>
#include<string.h>
const int maxn=1000007;
#define ll long long
char str[maxn];
int n;
int main()
{
while(scanf("%s",str)!=EOF)
{
n=strlen(str);
int zero=0,i;
ll count=0;
for(i=0;i<n;i++)
{
ll cur=0,co=1;
int length;
for(length=0;length<7;length++)
//计算出从i开始的前7位数字 这里也可以设置为10 11 等等因为10^6 和 10^7 10^8一样都是64的倍数 如果要改下面的6也是要改的
{
if(i-length<0) break;//如果没有这么多数 就直接退出
cur+=(str[i-length]-'0')*co;
if(!length||str[i-length]!='0')//!length 是为了找到单独为0的串 str[i-length]!='0'防止出现0开头的串
{
if(cur%64==0)
++count;
}
co*=10;
// printf("cur=%I64d\n",cur);
}
//printf("count=%d,zero=%d\n\n",count,nonzero);
/*下面的程序是记录i之前有多少个非0数 因为12345678 8同为
1234567 123456 12345等的后六位 所以一旦这个后六位可以被整出 那么将是所有前面串的后六位
所以要记录下来多少个非0数 非0是为了不出现0开头的数*/
if(cur%64==0)
count+=zero;
if(i>=6&&str[i-6]!='0')//注意细节 这里是6哦 自己随便找组数据就能看出来了 千万注意细节
++zero;
}
printf("%lld\n",count);
}
return 0;
}