【Number Theory?】【HDU - 4215】(思维+打表)

题目:

In number theory, for a positive number N, two properties are often mentioned, one is Euler's function, short for E(N), another is factor number, short for F(N). 
To be more precise for newbie, here we recall the definition of E(N) and F(N) again. 
E(N) = |{i | gcd(N, i) = 1, 1 <= i <= N}| 
F(N) = |{i | N % i = 0, 1 <= i <= N}| 
Here |Set| indicates the different elements in the Set. 
As a number fanaticism, iSea want to solve a simple problem now. Given a integer N, try to find the number of intervals [l, r], l is no bigger than r obviously, strictly fit in the interval [1, N]. It's a piece of cake for clever you, of course. But here he also has another troublesome restrict: 

 

Input

The first line contains a single integer T, indicating the number of test cases. Each test case includes one integer N. 

Technical Specification 
1. 1 <= T <= 1 000 
2. 1 <= N <= 1 000 000 000 

Output

For each test case, output the case number first, then the number of intervals.

Sample Input

2
2
9

Sample Output

Case 1: 1
Case 2: 6

 

解题报告:问从1-n的区间里边,有多少个区间 [l,r] 满足这个区间中的欧拉数和因子数相同,解题思路刚上来是无解,后来自己开始尝试着打表,将1-1000的运行结果输出来,会发现规律,就是大于等于30的时候就是10这个数字,在小于30的时候是存在一个数组与之相对应的 ,之间对应其下标的数字就可以!

ac代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;

//int gcd(int a,int b)
//{
//	if(b==0)
//		return a;
//	else
//		return gcd(b,a%b);
//}
//const int maxn=1e3+100;
//
//int num[maxn][maxn];
//int sum1[maxn];
//int sum2[maxn];
//int ans[maxn];
//int main()
//{
//	int n=100;
//	for(int i=1;i<=n;i++)
//	{
//		int a=0,b=0;
//		int cnt=0;
//		for(int j=1;j<=i;j++)
//		{
//			if(i%j==0)
//				a++;
//			if(gcd(i,j)==1)
//				b++;
//			
//		}	
//		sum1[i]=sum1[i-1]+a;
//		sum2[i]=sum2[i-1]+b;
//		for(int j=0;j<=i;j++)
//		{
//			for(int k=j+1;k<=i;k++)
//			{
//				if(sum1[k]-sum1[j]==sum2[k]-sum2[j])
//					cnt++;
//			}
//		}
//		ans[i]=cnt;
//	}for(int i=0;i<n;i++)
//		printf("%d\n",ans[i]);
//}
//0,1,1,2,2,4,5,5,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,9,9,9,9,9,9,10……(全是10)
int ans[40]={0,1,1,2,2,4,5,5,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,9,9,9,9,9,9};

int main()
{
	int t,n;
	scanf("%d",&t);
	for(int kase=1;kase<=t;kase++)
	{
		scanf("%d",&n);
		if(n>=30)
			printf("Case %d: 10\n",kase);
		else
			printf("Case %d: %d\n",kase,ans[n]);
	} 
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值