codeforces 495B Modular Equations 简单数论~

链接:http://codeforces.com/problemset/problem/495/B

首先 a = b(mod x)  可以根据同余定理 b|a-b . 然后从1开始枚举到a-b。 还有一个定理,在sqrt(a-b)范围内 就可以枚举出所有的因子式,例如16,sqrt(16) = 4 , 1 * 16 = 16, 2*8 = 16, 4*4 = 16

再没有其它的式子了(卡在这里了。。。);;

/*************************************************************************
    > File Name: cf_282_B.cpp
    > Author:
    > Mail:
    > Created Time: 2014年12月14日 星期日 18时05分04秒
 ************************************************************************/

#include<iostream>
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    if( n == m )
    {
        cout<<"infinity"<<endl;
        return 0;
    }
    if(n<m)
    {
        cout<<0<<endl;
        return 0;
    }
    int res = 0;
    n-=m;
    for(int i=1; i*i<=n; i++)
    {
        if(n%i==0&&i>m)
            res++;
        if(n%i == 0 && n/i > m && n/i != i)
            res++;
    }
    cout<<res<<endl;
    return 0;
}
时间: 2024-08-07 08:40:02

codeforces 495B Modular Equations 简单数论~的相关文章

codeforces 495B. Modular Equations 解题报告

题目链接:http://codeforces.com/problemset/problem/495/B 题目意思:给出两个非负整数a,b,求出符合这个等式      的所有x,并输出 x 的数量,如果 x 有无限多个,那么输出 infinity. 想了半个多小时......有个地方想遗漏了. a mod x == b,等价于  a = k*x + b.设 mul = a - b,那么 k*x = mul,然后就不断枚举 mul 的因子,即 kx = mul.由于 mod 出来的结果为 b,那么

cf 495b Modular Equations

#include<cstdio> #include<cmath> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int a,b,x; while(scanf("%d%d",&a,&b)!=EOF) { if(a<b) { printf("0\n");

数学 Codeforces Round #282 (Div. 2) B. Modular Equations

题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1,那么24,12, 8, 6, 4, 3, 2都可以,所以只要求出k的约数有几个就可以了,a <= b的情况要特判 /************************************************* Author        :Running_Time* Created Time  

hdu 1395 2^x mod n = 1 (简单数论)

题目大意: 求出一个最小的x 使得 2的x次方对n取模为1 思路分析: 若要 a*b%p=1  要使得b存在 则 gcd (a,p)=1. 那么我们应用到这个题目上来. 当n为偶数 2^x 也是偶数,那么gcd 肯定不是1.故这个是不存在的. 那么n为奇数的时候,也就一定是1了. 所以直接暴力找. #include <iostream> #include <cstdio> using namespace std; int main() { int n; while(scanf(&q

HDOJ 1163 Eddy&#39;s digital Roots(简单数论)

[思路]:http://blog.csdn.net/iamskying/article/details/4738838 求解思路: 现在分析一个问题,假设将十位数为a,个位数为b的一个整数表示为ab,则推导得 ab*ab = (a*10+b)*(a*10+b) = 100*a*a+10*2*a*b+b*b 根据上式可得:root(ab*ab) = a*a+2*a*b+b*b = (a+b)*(a+b);[公式一] 同理也可证得:root(ab*ab*ab) = (a+b)*(a+b)*(a+b)

CodeForces 30C Shooting Gallery 简单dp

题目链接:点击打开链接 给定n个气球 下面n行 x y t val 表示气球出现的坐标(x,y) 出现的时刻t,气球的价值val 枪每秒移动1个单位的距离 问: 射击的最大价值,开始时枪瞄准的位置任意. 思路: dp一下.. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <math.h> #include <set

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

Codeforces 837E Vasya&#39;s Function 数论 找规律

题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a,b),那么b-GCD(a,b) = (B-1)*GCD(a,b),如果此时A和B-1依然互质,那么GCD不变下一次还是要执行b-GCD(a,b).那么GCD什么时候才会变化呢?就是说找到一个最小的S,使得(B-S)%T=0其中T是a的任意一个因子.变形得到:B%T=S于是我们知道S=min(B%T).也

Codeforces 837E Vasya&#39;s Function - 数论

Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b. Vasya has two numbers x and y, and he wants to calculate f(x, y).