数论 GCD 最大公约数 欧拉函数经典题 洛谷 CF1295D Same GCDs Codeforces1295D

​前言

两个月了,我终于更了……

这两个月忙(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 0x<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 1T50) — 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} 1a<m1010) .

输出格式

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=1n[gcd(a,m)=gcd(a+x,m)]

多组测试数据, T ≤ 50 , 1 ≤ a < m ≤ 10 T≤50, 1≤a<m≤10 T50,1a<m10

输入输出样例

输入 #1
3
4 9
5 10
42 9999999967
输出 #1
6
1
9999999966

​说明/提示

In the first test case appropriate x x x -s are [

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值