Codeforces Round #282 (Div. 2) B.(数学)
2015-01-07 17:47
253 查看
题目链接:http://codeforces.com/contest/495/problem/B
解题思路:
求a % x == b,可以得知(a - b) % x == 0,x > b。
当a == b时,一定有无穷多解;当a < b时,输出0;其余情况输出(a - b)的所有因子。这里加一个优化,每次只扫 i ,然后分别判断 i 和 a -b是否满足大于b的情况 。
完整代码:
解题思路:
求a % x == b,可以得知(a - b) % x == 0,x > b。
当a == b时,一定有无穷多解;当a < b时,输出0;其余情况输出(a - b)的所有因子。这里加一个优化,每次只扫 i ,然后分别判断 i 和 a -b是否满足大于b的情况 。
完整代码:
#include <functional> #include <algorithm> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <numeric> #include <cstring> #include <climits> #include <cassert> #include <complex> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); //M_PI; int main() { #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int a , b; while(cin >> a >> b) { if(a == b) { cout << "infinity" << endl; continue; } else if(a < b) { printf("0\n"); continue; } int cnt = 0; int k = a - b; int i; for(i = 1 ; i * i < k ; i ++) { if(k % i == 0) { if(i > b) cnt ++; if(k / i > b) cnt ++; } } if(i * i == k && i > b) cnt ++; printf("%d\n",cnt); } }
相关文章推荐
- Codeforces Round #280 (Div. 2) E. Vanya and Field 数学
- SGU - 105 - Div 3 (简单数学题!)
- Codeforces Round #415 (Div. 2) C. Do you want a date? 数学
- Codeforces Round #369 (Div. 2) E. ZS and The Birthday Paradox 数学
- Codeforces Round #142 (Div. 1) C. Triangles 数学,完全图,统计贡献 2017/1/25
- Codeforces Round #133 (Div. 2) A. Tiling with Hexagons(数学)
- Codeforces #467 (Div. 2) C. Save Energy! ( 数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- MySQL数学函数之div的用法
- Codeforces Round #295 (Div. 2) C. DNA Alignment(数学水题)
- Codeforces Round #295 (Div. 2) C. DNA Alignment(数学)
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- Codeforces Round #136 (Div. 2) / 221A Little Elephant and Function (数学)
- Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和
- CodeForces Div1: 995 D. Game(数学期望)
- Codeforces Round #260 (Div. 2) B. Fedya and Maths (数学规律)
- Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya(组合数学)
- CF#275 (Div. 2) C(数学构造)
- Codeforces Round #448 (Div. 2)D. String Mark(组合数学)