首页 > 其他分享 >变相欧拉

变相欧拉

时间:2023-03-17 09:45:31浏览次数:24  
标签:int cin getans 变相 ret ans integer 欧拉

Problem Description
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the largest divisor common to a and b,For example,(1,2)=1,(12,18)=6.
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.

Input
The first line of input is an integer T(T<=100) representing the number of test cases. The following T lines each contains two numbers N and M (2<=N<=1000000000, 1<=M<=N), representing a test case.

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


输入样例

3
1 1
10 2
10000 72
 

输出样例

1
6
260
即 gcd(a,b) = m 对式子做一个简单的变化,同除m,即得到 gcd(a/m,b/m) = 1 也就是求b 除以一个大于等于m的因子后,比它小且与它互质的数有多少个
#include<bits/stdc++.h>

typedef long long LL;
const int MAXN = 3e6 + 10;
using namespace std;

int T;
int a,b;
LL ans;

int getans(int x)
{
    int ret = x;
    for(int i=2;i*i<=x;i++)
    {
        if(x % i == 0)
        {
            ret = ret - ret / i;
            while(x % i == 0) x /= i;    
        }    
    }
    if(x > 1) ret = ret - ret / x;
    return ret;    
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>T;
    while(T--)
    {
        cin>>a>>b;
        ans = 0;
        for(int i=1;i*i<=a;i++)
        {
            if(a % i == 0)
            {
                if(i >= b) ans += getans(a / i);
                if(a / i != i && a / i >= b) ans += getans(i);
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}
View Code

 

标签:int,cin,getans,变相,ret,ans,integer,欧拉
From: https://www.cnblogs.com/xxx3/p/17225479.html

相关文章

  • 【洛谷】P4139 上帝与集合的正确用法(扩展欧拉定理)
    原题链接题意求:\[2^{2^{2^{\ldots}}}\modp\]可以证明这个式子一定为一个常数。\(1\leqp\leq10^7\)思路根据扩展欧拉定理,可以得到:\[2^{2^{2^{\ldots}}}\equi......
  • 欧拉定理学习笔记
    费马小定理:当$a,p\in\mathbb{Z}$且\(p\)为质数,$a\not\equiv0\pmod{p}$时,有:\[a^{p-1}\equiv1\pmod{p}\]故\(a^b\equiva^{b\mod(p-1)}\pmod{p}\)欧......
  • 质数、约数、欧拉函数、欧几里得
    质数试除法判定质数boolisprime(intx){ if(x==1) returnfalse; if(x==2) returntrue; for(inti=2;i<=x/i;i++) if(x%i==0) returnfals......
  • 欧拉函数模板
    //求n的欧拉函数intcalPhi(intn){intret=n;intbd=std::sqrt(n);for(inti=2;i<=n/i;++i){if(n%i==0){......
  • 埃氏筛 & 欧拉筛
    Part1埃氏筛埃拉托斯特尼筛法,简称埃氏筛或爱氏筛,是一种由希腊数学家埃拉托斯特尼所提出的一种简单检定素数的算法。要得到自然数n以内的全部素数,必须把不大于根号n的所有......
  • 混合图欧拉回路(核心也就是网络流啦)
    于2023/2/22日的模拟赛遇到了这一东西。也是网络流应用的一种新模型,感觉是大有可为啊,写个博客记录下。给定一个图,里面的边有的是有向边,有的是无向边,要求给出无向边的定......
  • 华为认证欧拉openEuler-HCIA文本编辑器及文本处理
    文本编辑器及文本处理文本编辑器介绍常见的Linux文本编辑器有:emacsnanogeditkeditvivimLinux文本编辑器-emacsemacs是一款功能强大的编辑器,与其说是一款编辑器,它更像......
  • 最快素数打表,比欧拉筛快一倍。
    1e7内比欧拉筛子快一倍,2e7持平,之后略慢不论N多大整体计算次数,都是欧拉筛子的1/3,求大神解答1e8之后为什么变慢思路:相较于欧拉筛考虑1-n所有数,这里基于孪生素数,只需要考虑......
  • #10105. 「一本通 3.7 例 1」欧拉回路
     求欧拉回路(dfs) #include<bits/stdc++.h>usingnamespacestd;constintN=1e6+3,M=2e6+3;inlineintread(){intres=0,flag=1;ch......
  • 欧拉路 笔记
    欧拉路:从S到T不重复地经过图的所有边 存在性判定:有2个奇点(S,T),其他为偶点 欧拉回路:同欧拉路,但要求回到起点欧拉图:含有欧拉回路的图判定:(1)对无向图,所有点的度......