Discrete Logging hunnu10590 pku2417 fzu 1352 hit 1928 zoj 1898

以下轉自:http://hi.baidu.com/aekdycoin/blog/item/b317ca18bb24334942a9ad55.html【普通Baby Step Giant Step】【問題模型】求解A^x = B (mod C) 中 0 <= x < C 的解,C 為素數【思路】我們可以做一個等價x = i * m + j  ( 0 <= i < m, 0 <=j < m) m = Ceil ( sqrt( C)

Project Euler begin

problem 1If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below

hdu 3930 Broot 二次剩餘

模素數p的原根g的優美體現在每個模p的非零數以g的冪次出現。所以,對任何數1 <= a < p,我們可選擇冪         g,g^2,g^2,```````,g^(p-2),g^(p-1)中恰好一個與a模p同餘。相應的指數被稱為以g為底的a模p的指標。假設p與g已給定,則記指標為I(a)。以下以2模13的所有冪的形式:I          1   2  3    4   5   6   7   8    9  10   11 122^I(mod 13)   2  4  8  3 

poj 3734 Blocks 指數型母函數

遞推公式:E(t)=(1+t+t^2/2!+......+..)^2*(1+t^2/2!+t^4/4!+..+)^2                   =e^2t*((e^t+e^-t)/2)^2                   =1/4(e^4t+2*e^2t+1)                   =sigma(1/4*[4^n+2*2^n+1]*t^n/n!) n=0,1,2,,,  ==> a(n)=1/4(4^n+2*2^n)  /* * poj3734.c * *

hdu 1042 N!

 #include<stdio.h>#define nmax 100000int num[nmax];void solve(int n) {int i, j, k, r;for (i = 1, num[0] = 1, k = 0, r = 0; i <= n; i++) {for (j = 0; j <= k; j++) { num[j] = num[j] * i + r;if (num[j] >= nmax) {

pku 1811 Prime Test 大素數判定和大數分解

 /* * pku1811.c * * Created on: 2011-8-1 * Author: 王竹*/#include<stdio.h>#include<stdlib.h>#define LL long longLL pmin;LL modular_multi(LL a, LL b, LL c) { LL ret; ret = 0, a %= c;while (b) {if (b & 1) { ret +=

Perfect Pth Powers zoj 2124 pku1730 hunnu10585

測試資料中有負數。湖南師範大學(hunnu OJ)提交時要使用%I64d只要將n進行素因子分解,把所有素因子數目的gcd求出來就行。注意:n可能是負數,所以對於負數還需要將求出來的結果試除2,直到結果不是偶數才是最後負數的結果#include<stdio.h>#include<string.h>#include<math.h>#define nmax 65536int prime[nmax], plen, cfactor[nmax], clen;void

codeforces #139 A dice tower

 題意:給你n個骰子,擺成一個塔,且相鄰的骰子的接觸的面的數字不同。而你看到的只有頂部和某兩側,現在給你的就頂部和某兩側的數字,請問,能否唯一判定所有面的數字。解法:既然要唯一,且頂部的數(假設為z)確定了,那麼要不能唯一判定所有面的數字,那下面的某一個或幾個骰子的側面的數是z或7-z,如此,即可解題,代碼如下: import java.io.BufferedInputStream;import java.util.Scanner;public class Main { public

soj 3252 Choose 組合數對素數取餘

由於素數P很小,故先打階乘的餘數表(小於P的所有正數階乘對P的餘數表)。/* * soj3252.c * * Created on: 2011-10-10 * Author: bjfuwangzhu*/#include<stdio.h>#define nmod 10007int num[nmod];void init() {int i;for (i = 1, num[0] = 1; i < nmod; i++) { num[i] = num[i - 1

poj 2427 Smith’s Problem pell方程

import java.io.BufferedInputStream;import java.math.BigInteger;import java.util.Scanner;public class Main {public static BigInteger p, q;public static void solve(int n) {BigInteger N, p1, p2, q1, q2, a0, a1, a2, g1, g2, h1, h2;p1 = BigInteger.ZERO;p2

PKU 2429 GCD & LCM Inverse

大數分解pollard-rho素數判定miller-rabin#include<stdio.h>#include<time.h>#include<stdlib.h>#define LL unsigned long long#define nmax 2005LL factor[nmax], num[nmax], minx, ans;int flen, nnum;LL modular_multi(LL a, LL b, LL c) {LL ret;ret = 0,

soj 3137 Simple Computing 容斥原理 hdu 1796 How many integers can you find

/* * hdu1796.c * * Created on: 2011-10-3 * Author: bjfuwangzhu*/#include<stdio.h>#define LL long long#define nmax 11int num[nmax], nlen;LL res;int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}void dfs(int start, int c, int lcm,

hdu 4407 Sum 容斥原理

題意很簡單,就是給你一個數組大小為n的值從1到n,之後有m次操作,要麼修改前面的數組中的某一項,要麼是輸出從x到y(包括邊界)中的數與p互質的數的和。由於m很小(m<=1000)故,將修改的部分儲存下來之後統計輸出時,在判斷修改的部分是否與p互質,若是要修改原來的,在修改現在的。注意,就是多次修改同一個地方,只記錄最後一次。對於統計從x到y的與p互質數的和,有結果=數1到y的滿足要求的結果-數1到x-1的滿足要求的結果。而從1開始到n的數中與p互質的數的和的求法,就是個容斥原理的演算法。剔

POJ about lcm

由題知:g(n)=sigma{phi(n/d)*n/d},d|nf(n)=(g(n)+1)/2由於歐拉函數的積性,phi(n*m)=phi(n)*phi(m),gcd(n,m)=1所以,n=pi(pi^ci)故g(n)=g(pi(pi^ci))。g(n)=pi(g(pi^ci)g(pi^ci)=sigma(phi(pi^ci)pi^ci)而對於phi(pi^ci)(pi-1)*(pi^(ci-1)至此就這題就解決了!My Code:逾時的代碼:LL sumlcm(int n) {int te =

POJ2429 SCU2106 GCD & LCM Inverse

 #include<stdio.h>#include<math.h>#define LL long longLL a, b, x, y;LL gcd(LL p, LL q) { LL r = 1;while (r) { r = p % q;if (r) { p = q; q = r; } }return q;}LL solve() { LL i, te; b /= a;

Codeforces Round #140Div2

 What do I turn?很簡單,運用叉積即可得到答案。package com.wangzhu.codeforces;//What do I turn?import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Scanner;public class Round140Div2 { public

轉載 高效實用的異或操作

異或(XOR)是一種位元運算符,相同為0,相異為1如0^1=1,0^0=0,1^1=0異或滿足交換律、結合律a^b=b^aa^(b^c)=a^b^c=(a^b)^ca^b^c^d=a^d^c^b異或是一種位元運算,能夠高效地巧妙地完成一些功能1、  實現兩個數的交換,swap函數 public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j];arr[j] = arr[i] ^ arr[j];arr[i] =

toj 2991 Simple Task II 二次剩餘

  /* * toj2991.c * * Created on: 2011-10-13 * Author: bjfuwangzhu *//* 給出整數n,統計二次同餘方程x^2=1(mod n)在[0,n)閉區間上的解的個數。 分析: 根據《簡明數論》上的說明: 若p是素數,x^2=1(mod p^k)的解數有如下結論。 當p==2時,k==1則解數是1,k==2時解數是2,k>=3時,解數是4。 當p>2時,k>0時解數是2。 然後分解因數。

poj 3421 X-factor Chains 組合數學

給定一個數X.1=X0, X1, X2.....Xm = X 是X的因數求一串因數,要求Xi | Xi+1,即上一個因數能整除下一個因數,問這條串就的最長長度,和有多少條這樣長度的串.X = p1^a1 * p2^a2 ... pn^anXi = p1^b2 * p2^b2 ...pk^bk... pn^bn,Xi+1 = p1^b2 * p2^b2 ...pk^(bk+1)... pn^bn, 要使length最長,只要從1開始,每次只乘以X的一個質因數即可,即length = (a1+a2+

soj 3291 Distribute The Apples II DP

狀態轉移方程為:num[n][k]=num[n-1][k-1]+num[n-k][k]表示n個Apple分給k個People,1).若k個人不能獲得一樣的,則為了滿足題意,需要將最後一個人先分1個,再將剩餘n-1的分給k-1個人;2).若能,則就變成了將n-k個Apple分給k個People的子過程。/* * soj3291.c * * Created on: 2011-10-10 * Author:

總頁數: 61357 1 .... 9581 9582 9583 9584 9585 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.