138

明显的打表题,一开始想暴,发现太慢太慢了,后来加了个二分,很快就出答案了

打表程序如下

#include <iostream>
#include <cstdio>
using namespace std;

long long sum[100000000];
int l ,r, mid;

int main()
{

    for(long long i = 1;i <= 100000000;i++)
    {
        sum[i] = sum[i-1]+i;
    }
    for(long long i = 2;i <= 100000000;i++)
    {
        l = 1;
        r = i;
        while(l < r)
        {
            if(l == r||l+1 == r) break;
            mid = (l+r)/2;
            if((sum[i] - mid) == 2*(sum[mid]-mid))
            {
                printf("%10d%10d\n", mid, i);
                break;
            }
            else if((sum[i] - mid) > 2*(sum[mid]-mid))
            {
                l = mid;
            }
            else r = mid;
        }
    }
    return 0;
}
交的程序如下

#include <iostream>
#include <cstdio>
using namespace std;

string s[20] =
{
"         6         8",
"        35        49",
"       204       288",
"      1189      1681",
"      6930      9800",
"     40391     57121",
"    235416    332928",
"   1372105   1940449",
"   7997214  11309768",
"  46611179  65918161"
};
int main()
{
    for(int i = 0;i < 10;i++)
    {
        cout << s[i] << endl;
    }
    return 0;
}

posted @ 2011-05-19 01:05  KOKO's  阅读(105)  评论(0编辑  收藏  举报