码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3629 数学杂题

时间:2014-08-28 19:51:45      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   amp   sp   on   size   ef   c   



//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const int INF = 100000000;
const int MAXN = 100+20;
int cal(int x)
{
    ll ret=0;
    for(int i=1;i<=x;i++)
        ret+=x/i;
    if(ret%2)return 0;
    else return 1;
}
//int ans[MAXN];
ll a,b;
/*ll solve()
{
    ll sa=sqrt(a);
    ll sb=sqrt(b);
    ll flag;
    if(sa%2==0)flag=1;
    else flag=0;
    ll pos=a,ret=0;
    sa++;
    while(pos<=b && sa*sa-1<=b)////
    {
        ret+=flag*(sa*sa-pos);
        pos=sa*sa;
        sa++;
        flag=!flag;
    }
    if(pos<=b)
    {
        ret+=(b-pos+1)*flag;
    }
    return ret;
}*/
ll cal(ll x)
{
    if(x<0)return 0;
    if(x == 0)return 1;
    ll sx=sqrt(x);
    ll ret=0,fou;
    if(sx%2 == 0)
    {
        ret+=x-sx*sx+1;
        sx--;
        fou=sx/2;
        ret=ret-(fou+1)*(2*fou+3)+(sx+1)*(sx+1);
    }
    else
    {
        ret+=(sx+1)*(sx+1);
        sx--;////////
        sx/=2;
        ret-=(sx+1)*(2*sx+3);
    }
    return ret;
}
int main()
{
    while(~scanf("%lld%lld",&a,&b))
    {
        printf("%lld\n",cal(b)-cal(a-1));
    }
    return 0;
}


zoj 3629 数学杂题

标签:os   io   for   amp   sp   on   size   ef   c   

原文地址:http://blog.csdn.net/u011026968/article/details/38900867

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!