HYSBZ 2190 hdoj 2841 2824 《(打表)欧拉和求素数对+队列求1-n中与k互质个数》

59 篇文章 0 订阅
20 篇文章 0 订阅

Time Limit: 10000MS Memory Limit: 265216KB 64bit IO Format: %lld & %llu

 Status

Description

  作为体育委员,C君负责这次运动会仪仗队的训练。仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如下图)。       现在,C君希望你告诉他队伍整齐时能看到的学生人数。

Input

  共一个数N。

Output

  共一个数,即C君应看到的学生人数。

Sample Input

  4

Sample Output

  9


Hint

【数据规模和约定】   对于 100% 的数据,1 ≤ N ≤ 40000

Source

SDOI2008


让坐标从【0,0】到【n-1,n-1】

求素数对--不是素数对的一定被素数对坐标所屏蔽--【1,1】对算了两次--【0,1------n-1】和【1-----n-1,0】没算



代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
int shu[40100];
LL dui[40100];
void oula()
{
    memset(dui,0,sizeof(dui));
    LL i,j;dui[1]=1;
    for (i=2;i<40100;i++)
    {
        if (!dui[i])
        {
            dui[i]=i;
            for (j=i;j<40100;j+=i)
            {
                if (!dui[j])
                    dui[j]=j;
                dui[j]=dui[j]-dui[j]/i;
            }
        }
        dui[i]+=dui[i-1];
    }
}
int main()
{
    int n;
    oula();
    scanf("%d",&n);
    n--;
    printf("%d\n",dui[n]*2+1);
    return 0;
}


Visible Trees

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2673    Accepted Submission(s): 1161


Problem Description
There are many trees forming a m * n grid, the grid starts from (1,1). Farmer Sherlock is standing at (0,0) point. He wonders how many trees he can see.

If two trees and Sherlock are in one line, Farmer Sherlock can only see the tree nearest to him.
 

Input
The first line contains one integer t, represents the number of test cases. Then there are multiple test cases. For each test case there is one line containing two integers m and n(1 ≤ m, n ≤ 100000)
 

Output
For each test case output one line represents the number of trees Farmer Sherlock can see.
 

Sample Input
  
  
2 1 1 2 3
 

Sample Output
  
  
1 5
 

Source





题意:

一个人站在【0,0】处看【n,m】
一共能看到多少点---



代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
int su[35],ge;
LL dui[100100];
void oula()
{
    memset(dui,0,sizeof(dui));
    LL i,j;dui[1]=1;
    for (i=2;i<100100;i++)
    {
        if (!dui[i])
        {
            dui[i]=i;
            for (j=i;j<100100;j+=i)
            {
                if (!dui[j])
                    dui[j]=j;
                dui[j]=dui[j]-dui[j]/i;
            }
        }
        dui[i]+=dui[i-1];
    }
}
void Su(int xx)
{
    LL i;ge=0;
    for (i=2;i*i<=xx;i++)
    {
        if(xx%i==0)
            su[ge++]=i;
        while (xx%i==0)
            xx/=i;
    }
    if (xx>1)
        su[ge++]=xx;
}
LL sl(int xx)
{
    int qu[50000],kp=0;
    qu[kp++]=-1;
    LL lp=0;
    for (int i=0;i<ge;i++)
    {
        int ll=kp;
        for (int j=0;j<ll;j++)
            qu[kp++]=qu[j]*su[i]*(-1);
    }
    for (int i=1;i<kp;i++)
    lp+=xx/qu[i];
    return lp;
}
LL s;
int main()
{
	int t;scanf("%d",&t);
	oula();
	while (t--)
	{
	    int a,b,c;
	    scanf("%d%d",&a,&b);
	    if (a>b)
        {
            c=a;a=b;b=c;
        }
	    s=dui[a]*2-1;
	    for (int i=a+1;i<=b;i++)
        {
            Su(i);
            s+=a-sl(a);
        }
        printf("%lld\n",s);
	}
	return 0;
}

Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u

 Status

Description

The Euler function phi is an important kind of function in number theory, (n) represents the amount of the numbers which are smaller than n and coprime to n, and this function has a lot of beautiful characteristics. Here comes a very easy question: suppose you are given a, b, try to calculate (a)+ (a+1)+....+ (b)
 

Input

There are several test cases. Each line has two integers a, b (2<a<b<3000000).
 

Output

Output the result of (a)+ (a+1)+....+ (b)
 

Sample Input

    
    
3 100
 

Sample Output

    
    
3042
 

Source

2009 Multi-University Training Contest 1 - Host by TJU

此打表不超时--可算n/1+n/2+............n/n=== 45221766    n/1+n/2+n/3+.........n/n可   点击打开链接


代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL  __int64
int shu[3000000];
LL dui[3001000];
void oula()
{
    memset(dui,0,sizeof(dui));
    LL i,j;dui[1]=1;
    for (i=2;i<3001000;i++)
    {
        if (!dui[i])
        {
            dui[i]=i;
            for (j=i;j<3001000;j+=i)
            {
                if (!dui[j])
                    dui[j]=j;
                dui[j]=dui[j]-dui[j]/i;
            }
        }
        dui[i]+=dui[i-1];
    }
}
int main()
{
    int n;
    oula();
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        printf("%I64d\n",dui[b]-dui[a-1]);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值