A - Matrix 字符串 + 数学

 

A - Matrix
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status
Appoint description: System Crawler  (2013-11-23)

Description

You have a string of decimal digits s. Let's define bij = si·sj. Find in matrix b the number of such rectangles that the sum bij for all cells(i, j) that are the elements of the rectangle equals a in each rectangle.

A rectangle in a matrix is a group of four integers (x, y, z, t)(x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.

Input

The first line contains integer a (0 ≤ a ≤ 109), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).

Output

Print a single integer — the answer to a problem.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Sample Input

Input
10
12345
Output
6
Input
16
439873893693495623498263984765
Output
40

 

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 4010;
char s[maxn];
LL b[maxn][maxn];
LL sum[maxn];
map<LL,LL> mp;
int main() 
{
    //freopen("in.txt","r",stdin);
    LL a;
    while(cin>>a)
    {
        scanf("%s",s+1);
        int len = strlen(s+1);
        int n  = len;
        LL ans = 0;
        sum[0] = 0;
        LL cnt = 0;
        repf(i,1,n)
            sum[i] = sum[i - 1] + s[i] - '0';
        
        repf(i,1,n)
            repf(j,i,n)
            {
                LL temp = sum[j] - sum[i-1];
                mp[temp] = mp[temp] + 1;
            }
        
        if(a == 0)
        {
            rep(i,1,50000)
                ans += mp[0]*mp[i];
            ans *= 2;
            ans += mp[0]*mp[0];
            cout<<ans<<endl;
            continue;
        }
        for(LL i = 1;i < 50000;++i)
        {
            if(a%i == 0)
            {
                ans += mp[i]*mp[a/i];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

 

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3444549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值