• A


    A - Matrix
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    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;
    }
     
  • 相关阅读:
    使用JavaScript获取select元素选中的value和text
    EF应用一:Code First模式
    EF常用查询语句
    在EF中执行SQL语句
    c++学习笔记之继承篇
    pyqt系列原创入门教程
    python sorted排序用法详解
    常见排序算法-Python实现
    作品集
    deepin系统如何安装deb格式的软件
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3444549.html
Copyright © 2020-2023  润新知