zoukankan      html  css  js  c++  java
  • UVa12465

    求能使a,b同余的正整数m的个数,即a,b差的因子个数。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <cstdlib>
     6 #include <climits>
     7 #include <sstream>
     8 #include <fstream>
     9 #include <cstdio>
    10 #include <string>
    11 #include <vector>
    12 #include <queue>
    13 #include <cmath>
    14 #include <stack>
    15 #include <map>
    16 #include <set>
    17 
    18 using namespace std;
    19 typedef pair<int,int> II;
    20 typedef vector<int> IV;
    21 typedef vector<II> IIV;
    22 typedef vector<bool> BV;
    23 typedef long long i64;
    24 typedef unsigned long long u64;
    25 typedef unsigned int u32;
    26 #define For(t,v,c) for(t::const_iterator v=c.begin();v!=c.end();++v)
    27 #define IsComp(n) (_c[n>>6]&(1<<((n>>1)&31)))
    28 #define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))
    29 const int MAXP = 46341;
    30 const int SQRP = 216;
    31 int _c[(MAXP>>6)+1];
    32 IV primes;
    33 void prime_sieve()
    34 {
    35     for ( int i = 3; i <= SQRP; i += 2 )
    36         if ( !IsComp(i) ) for ( int j = i*i; j <= MAXP; j+=i+i ) SetComp(j);
    37     primes.push_back ( 2 );
    38     for ( int i = 3; i <= MAXP; i += 2 ) if ( !IsComp(i) ) primes.push_back ( i );
    39 }
    40 
    41 int count_divisors ( int n )
    42 {
    43     int ret = 1;
    44     int sn = sqrt ( n );
    45     For ( IV, it, primes ) {
    46         int prime = *it;
    47         if ( prime > sn ) break; if ( n % prime ) continue;
    48         int e = 0; for ( ; n%prime == 0; e++, n/= prime );
    49         ret *= e+1;
    50         sn = sqrt(n);
    51     }
    52     if ( n > 1 ) ret *= 2;
    53     return ret;
    54 }
    55 int main()
    56 {
    57     prime_sieve ( );
    58     int a,b;
    59     while(scanf("%d%d",&a,&b)!=EOF)
    60     {
    61         if(a==0&&b==0)
    62         break;
    63         printf("%d\n",count_divisors(abs(a-b)))  ;
    64     }
    65 
    66 
    67     return 0;
    68 }
  • 相关阅读:
    jQuery工具函数
    jqXHR对象
    跨域获取
    Ajax :六个全局事件
    表单序列化
    Ajax : $. get()和$.post() $.getScript $.getJSON
    Ajax : load()
    列队动画
    关于MindManager显示不同级别的控制
    Mybatis 查询传多个参数(3中方法)
  • 原文地址:https://www.cnblogs.com/Acgsws/p/3130963.html
Copyright © 2011-2022 走看看