ZJUT 1277 素数的位数和 (不是水题胜似水题)

34 篇文章 0 订阅

不想说什么,输入只有不到300种,直接暴力打表吧。

#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
//int wei;
int a[7][60] = 
{
	{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 1, 0, 2, 2, 0, 2, 3, 0, 3, 3, 0, 1, 1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 1, 0, 2, 4, 0, 7, 7, 0, 12, 13, 0, 16, 16, 0, 13, 18, 0, 12, 11, 0, 6, 4,0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 4, 8, 0, 20, 19, 0, 31, 52, 0, 67, 77, 0, 93, 101, 0, 116, 95, 0, 92, 91, 0, 63, 51, 0, 29, 30, 0, 16, 5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 4, 12, 0, 28, 45, 0, 95, 143, 0, 236, 272, 0, 411, 479, 0, 630, 664, 0, 742, 757, 0, 741, 706, 0, 580, 528, 0, 379, 341, 0, 205, 166, 0, 84, 62, 0,34, 13, 0, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 2, 14, 0, 58, 76, 0, 204, 389, 0, 660, 852, 0, 1448, 1971, 0, 2832,3101, 0, 4064, 4651, 0, 5393, 5376, 0, 5570, 5785, 0, 5287, 4796, 0, 3975, 3671, 0, 2687, 2080, 0, 1405, 1135, 0, 630, 405, 0, 178, 140, 0, 51, 16, 0, 3, 1, 0,0, 0, 0, 0, 0}
};
/*
int getSum(int n)
{
	int sum = 0;
	wei = 0;
	while(n != 0)
	{
		sum += n % 10;
		n = n / 10;
		wei++;
	}
	return sum;
}
*/
int main()
{
	int i;
	int te;
	int s;
	int b;
	int sum;
	int d;
	int j;
	/*
	for(i = 2; i < 1000000; i++)
	{
		d = 1;
		for(j = 2; j <= (int)sqrt(i) && d == 1; j++)
		{
			if(i % j == 0)
			{
				d = 0;
				continue;
			}
		}
		if(d == 1)
		{
			sum = getSum(i);
			a[wei][sum]++;	
		}
	}
	for(i = 0; i < 7; i++)
	{
		printf("{");
		for(j = 0; j < 60; j++)
		{
			printf("%d, ", a[i][j]);	
		}	
		printf("}");
		printf("\n");
	}
	*/
	scanf("%d", &te);
	while(te--)
	{
		scanf("%d %d", &s, &b);
		if(b <= 60)
		{
			printf("%d\n", a[s][b]);
		}
		else
		{
			printf("0\n");
		}	
	}
	return 0;
}


 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值