前言
两个月了,我终于更了……
这两个月忙(chen)于(mi)内(xiang)卷(le),现在终于出新文章啦,(也算兑现了当初的出数论题文章的承诺)~
不说废话了,今天给大家介绍一道CF/洛谷上的数论题———CF1295D Same GCDs/1295D #81 Problem D。
这是一道相当不错的题,很考验选手的思维能力以及数学基础,先贴个题面~
洛谷题目传送门 or Codeforces题目传送门
题目描述
You are given two integers a a a and m m m . Calculate the number of integers x x x such that 0 ≤ x < m 0≤x<m 0≤x<m and g c d ( a , m ) gcd(a, m) gcd(a,m) = g c d ( a + x , m ) gcd(a + x, m) gcd(a+x,m).
Note: gcd(a, b) is the greatest common divisor of a a a and b b b .
输入格式
The first line contains the single integer T T T( 1 ≤ T ≤ 50 1≤T≤50 1≤T≤50) — the number of test cases.
Next T lines contain test cases — one per line. Each line contains two integers a a a and m m m ( 1 ≤ a < m ≤ 1 0 10 1≤a<m≤10^{10} 1≤a<m≤1010) .
输出格式
Print T T T integers — one per test case. For each test case print the number of appropriate x x x -s.
题意翻译
求 ∑ i = 1 n [ g c d ( a , m ) = g c d ( a + x , m ) ] \displaystyle\sum_{i=1}^n[ gcd(a,m)=gcd(a+x,m) ] i=1∑n[gcd(a,m)=gcd(a+x,m)]
多组测试数据, T ≤ 50 , 1 ≤ a < m ≤ 10 T≤50, 1≤a<m≤10 T≤50,1≤a<m≤10
输入输出样例
输入 #1
3
4 9
5 10
42 9999999967
输出 #1
6
1
9999999966
说明/提示
In the first test case appropriate x x x -s are [