zoukankan      html  css  js  c++  java
  • 费大马定理

    费大马定理:

                      

    奇偶数列法则:

     

    经典例题:HDU——6441

      1 #include <bits/stdc++.h>
      2 #include <time.h>
      3 #include <set>
      4 #include <map>
      5 #include <stack>
      6 #include <cmath>
      7 #include <queue>
      8 #include <cstdio>
      9 #include <string>
     10 #include <vector>
     11 #include <cstring>
     12 #include <utility>
     13 #include <cstring>
     14 #include <iostream>
     15 #include <algorithm>
     16 #include <list>
     17 using namespace std;
     18 //cout<<setprecision(10)<<fixed;
     19 #define eps 1e-6
     20 #define PI acos(-1.0)
     21 #define lowbit(x) ((x)&(-x))
     22 #define zero(x) (((x)>0?(x):-(x))<eps)
     23 #define mem(s,n) memset(s,n,sizeof s);
     24 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
     25 typedef long long ll;
     26 typedef unsigned long long ull;
     27 const int maxn=1e6+5;
     28 const ll Inf=0x7f7f7f7f7f7f7f;
     29 const ll mod=1e6+3;
     30 //const int N=3e3+5;
     31 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
     32 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
     33 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
     34 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
     35 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
     36 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
     37 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
     38 int Abs(int n) {
     39   return (n ^ (n >> 31)) - (n >> 31);
     40   /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
     41      若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
     42      需要计算 n 和 -1 的补码,然后进行异或运算,
     43      结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
     44 }
     45 ll binpow(ll a, ll b) {
     46   ll res = 1;
     47   while (b > 0) {
     48     if (b & 1) res = res * a%mod;
     49     a = a * a%mod;
     50     b >>= 1;
     51   }
     52   return res%mod;
     53 }
     54 void extend_gcd(ll a,ll b,ll &x,ll &y)
     55 {
     56     if(b==0) {
     57         x=1,y=0;
     58         return;
     59     }
     60     extend_gcd(b,a%b,x,y);
     61     ll tmp=x;
     62     x=y;
     63     y=tmp-(a/b)*y;
     64 }
     65 ll mod_inverse(ll a,ll m)
     66 {
     67     ll x,y;
     68     extend_gcd(a,m,x,y);
     69     return (m+x%m)%m;
     70 }
     71 ll eulor(ll x)
     72 {
     73    ll cnt=x;
     74    ll ma=sqrt(x);
     75    for(int i=2;i<=ma;i++)
     76    {
     77     if(x%i==0) cnt=cnt/i*(i-1);
     78     while(x%i==0) x/=i;
     79    }
     80    if(x>1) cnt=cnt/x*(x-1);
     81    return cnt;
     82 }
     83 int main()
     84 {   
     85     int t,n,a,b,c;
     86     scanf("%d",&t);
     87     while(t--)
     88     {
     89        scanf("%d%d",&n,&a);
     90         if(n==1)
     91         {
     92             printf("%d %d
    ",a+1,a+a+1);
     93             continue;
     94         }
     95         else if(n==2)
     96         {
     97             if(a%2==0)
     98             {
     99                 b=(a/2)*(a/2)-1;
    100                 c=(a/2)*(a/2)+1;
    101                 printf("%d %d
    ",b,c);
    102             }
    103             else if(a%2)
    104             {
    105                 b=(a/2)*(a/2)+(a/2+1)*(a/2+1)-1;
    106                 c=(a/2)*(a/2)+(a/2+1)*(a/2+1);
    107                 printf("%d %d
    ",b,c);
    108             }
    109             continue;
    110         }
    111       puts("-1 -1");
    112     }
    113     return 0;
    114 }
    View Code
  • 相关阅读:
    [转载]android开发手册
    [转载]windows phone7 学习笔记10——生命周期/墓碑化
    [转载]Windows Phone 系列 本地数据存储
    【转载】windows phone7 学习笔记12——推送通知服务
    【转载】windows phone7 学习笔记15——Bing Maps
    [转载]WP7交互特性浅析及APP设计探究
    【】windows phone7 学习笔记11——启动器与选择器
    [转载]支持的 Windows Phone 媒体编解码器
    【转载】wp7屏幕截图代码
    【转载】windows phone7 学习笔记14——地理位置服务与反应性扩展框架
  • 原文地址:https://www.cnblogs.com/zpj61/p/13607172.html
Copyright © 2011-2022 走看看