TOJ 2793.A Simple Problem

题目链接:http://acm.tju.edu.cn/toj/showp2793.html


2793.    A Simple Problem
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 554    Accepted Runs: 266



Given a nonnegative integer  a, and a positive integer  N, we define:

f(a, 1) = a 
f(ak) = f(ak - 1) * f(ak - 1) % Nk > 1

There may or may not exist some positive integer k satisfying f(ak) = 0.

Your task is, given a positive integer N, to determine how many a (0 ≤ a ≤ N) there are, such that for some positive integer k, f(ak) = 0.

Input

The input contains an integer  T on the first line, indicating the number of test cases. Each test case contains only one positive integer  N (1 ≤  N ≤ 1000000000) on a line.

Output

For each test case, output the answer on a single line.

Sample Input

6
2
12
50
180
245
361

Sample Output

2
3
6
7
8
20


Source: The 5th UESTC Programming Contest
Submit   List    Runs   Forum   Statistics

数论题目,好好分析就可得出,要使f(ak)=0,则a必须是N的所有素因数乘积的倍数,知道这一点后只需要求出素因数乘积p即可。


#include <stdio.h>
using namespace std;
bool isPrime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)
			return false;
	}
	return true;
}
int main(){
	int t,n,p;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		int tag=n;
		p=1;
		if(n==1)
			p=1;
		else if(isPrime(n))
			p=n;
		else{
			for(int i=2;i<=n;i++)
				if(n%i==0 && isPrime[i]){
					p*=i;
					while(n%i==0)
						n/=i;
				}
		}
		printf("%d\n",tag/p+1);
	}
} 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值