An Irreducible Fraction

探讨了素数在现代加密技术中的应用,特别是公钥加密系统如何利用素数的特性提高安全性,并介绍了RSA加密系统的原理及其实现过程。

Though prime numbers used to belong to pure mathematics traditionally, they’re more related now to our real world thanks to the development of cryptology and computers in late 20th century.
The public-key cryptography has introduced the concept, ‘it is easy to encode but hard to decode,’ increasing the convenience and reliability of the cryptography system.
Another concept, ‘it is easy to calculate but hard to inverse calculate,’ applies to integer factorization.
RSA cryptography system, which uses such a characteristic of integer factorization, encodes by multiplication of p and q (p*q), a very large prime number each, but needs to know what each p and q exactly is to decode it.
For example, it is easy to multiply two five-digit numbers, but in a given formula, ‘p*q = 1459160519,’ it will take long to find the right p and q pair (34583, 42193).
In reality, the numbers used by RSA are prime numbers of hundreds of digits.
For this reason, two issues have gained importance: primality test, which assesses whether a large number is a prime number or not, and prime factorization algorithms of such large numbers.
The cryptography system in development process by our company’s research lab is also based on irreducible fractions where such algorithms can be applied.
Figure out the problem below in order to help us design a safe and easy to use cryptography system that is right for mobile devices.

When a number N is given, use another number (≤ N) and find out all possible irreducible fractions. (≥ 0, ≤ 1)
For example, if N = 5, the number of possible irreducible fractions are 11 as below.


0 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1


Time limits: 1 second(java: 2 seconds)


Input format

Input may include many test cases. The number of test cases, T, is given on the first line of input and then the amount of T of test cases is given in a line. (T ≤ 30) N is given for the first line of each test case. (1 ≤ N ≤ 160)

Output Format


Output the number of cases of possible irreducible fractions for the first line of each test case.


Input Example


1
5


Output Example


11


int GCD(int num1,int num2)
{
 if(num2==0)
	 return num1;
else	 
   return GCD(num2,(num1%num2));

}
int IrreducibleFractions(int N)
{
	
	if(N==1)
		return 2;//0,1
	else
	{
		int i=0;
		int count=0;
		for(i=1;i<N;i++)
		{
			if(GCD(N,i)==1)//if GCD is 1 means it is not reducible anymore
				count++;
		}	
		return count+IrreducibleFractions(N-1);
	}
	
}
int main()
{
	int T,tc,N;

		scanf("%d", &T);
		for(tc = 0; tc < T; tc++)
		{
			scanf("%d",&N);
			printf("%d\n",IrreducibleFractions(N));
		}
}

include <stdio.h>

int T,N,l,m,n;

//int NA[161];


int GCD(int a, int b)
{
	if (b==0) return a;
	return GCD(b,a%b);
}



int main()
{
	scanf("%d",&T);
	while(T--){
		n=0;
		scanf("%d",&N);

		for(l=1;l<=N;l++)
			for(m=2;m<=N;m++)
			{
				if(l<m && GCD(l,m)==1)
					n++;


			}


			printf("%d\n",n+2);
	}

	return 0;
}


D. Segments Covering time limit per test2 seconds memory limit per test256 megabytes    There is a linear strip divided into m cells, numbered from 1 to m from left to right. You are given n segments. Each segment is defined by four numbers: l , r , p and q — the segment covers cells from l to r inclusively and exists with probability pq (independently). Your task is to calculate the probability that each cell is covered by exactly one segment. AI 翻译    有一个线性长条被分成了 m 个格子,从左到右依次编号为 1 到 m 。 给定 n 个区间。每个区间由四个数定义:l 、r 、p 和 q —— 该区间覆盖从 l 到 r (包含 l 和 r )的格子,且该区间存在的概率为 pq (各区间相互独立)。 你的任务是计算每个格子恰好被一个区间覆盖的概率。    Input The first line contains two integers n and m (1≤n,m≤2⋅105 ). Then n lines follow. The i -th of them contains four integers li , ri , pi and qi (1≤li≤ri≤m ; 1≤pi<qi<998244353 ). AI 翻译    输入 第一行包含两个整数 n 和 m (1≤n,m≤2⋅105 )。 接下来有 n 行。其中第 i 行包含四个整数 li 、ri 、pi 和 qi (1≤li≤ri≤m ;1≤pi<qi<998244353 )。    Output Print a single integer — the probability that each cell is covered by exactly one segment, taken modulo 998244353 . Formally, the probability can be expressed as an irreducible fraction xy . You have to print the value of x⋅y−1mod998244353 , where y−1 is an integer such that y⋅y−1mod998244353=1 . AI 翻译    输出 输出一个整数 —— 每个单元格恰好被一个线段覆盖的概率,对 998244353 取模。 形式上,该概率可以表示为一个既约分数 xy 。你需要输出 x⋅y−1mod998244353 的值,其中 y−1 是一个整数,满足 y⋅y−1mod998244353=1 。 Examples InputCopy 3 3 1 2 1 3 3 3 1 2 1 3 2 3 OutputCopy 610038216 InputCopy 2 3 1 2 1 2 2 3 1 2 OutputCopy 0 InputCopy 8 5 1 3 1 2 1 5 1 6 1 4 4 5 5 5 1 7 4 5 1 2 4 5 2 5 3 3 2 7 1 2 1 3 OutputCopy 94391813    Note In the first example, the probability is equal to 518 . AI 翻译    注意 在第一个示例中,概率等于 518 。解决这个问题,并且给我一个c++代码
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值