C Looooops [exgcd]
#include<bits/stdc++.h> #define LL long long using namespace std; int A,B,C,k; LL x,y,gcd; void exgcd(LL a,LL b){ if(!b){x=1,y=0,gcd=a; return;} exgcd(b,a%b); LL x1=y,y1=x-a/b*y; x=x1,y=y1; } int main(){ while(1){ scanf("%d%d%d%d",&A,&B,&C,&k); if(A==0) break; if(A==B){printf("0\n"); continue;} LL b=(LL)1<<k,c=B-A,a=C; exgcd(a,b); if(c%gcd){printf("FOREVER\n"); continue;} x *= c/gcd; x %= (b/gcd); x = (x+b/gcd) % (b/gcd); printf("%lld\n",x); }return 0; }
相關推薦
POJ 2115 C-Looooops | exgcd
span type () int spa eve scanf while algo 題目 給出一個循環for(int i=A;i!=B;i+=C) 在mod (1<<k) 下是否可以退出循環 是,輸出時間,否輸出FORVEER 題解: 題意可以變換成 A+
C Looooops [exgcd]
傳送門 #include<bits/stdc++.h> #define LL long long using namespace std; int A,B,C,k; LL x,y,gcd; void exgcd(LL a,LL b){ if(!b){x=1,y=0,gcd
POJ 2115 C Looooops(exgcd—解一元線性同餘方程)
C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23820 Accepted: 6591 De
POJ 2115 C Looooops(模線性方程)
blank str using while eve printf b- get %d http://poj.org/problem?id=2115 題意: 給你一個變量,變量初始值a,終止值b,每循環一遍加c,問一共循環幾遍終止,結果mod2^k.如果無法終止則輸出FO
poj2115 C Looooops
div ooo return main oops long logs oooo iostream 思路: 求最小的非負整數t使得C * t % 2k = (B - A) % 2k。 實現: 1 #include <iostream> 2 #include
poj2115 C Looooops——擴展歐幾裏得
type names turn spa void continue targe pan ace 題目:http://poj.org/problem?id=2115 就是擴展歐幾裏得唄; 然而忘記除公約數... 代碼如下: #include<iostream>
POJ ~ 2115 ~ C Looooops (擴充套件歐幾里得)
題解 設答案為x,由題意得,同餘方程 => 。 然後求得最小的非負整數解 x 就是答案。 //#include<bits/stdc++.h> #include<iost
Poj 2115 C Looooops 擴充套件歐幾里得
Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) sta
C Looooops(歐幾里德+poj2115)
The input consists of several instances. Each instance is described by a single line with four integers A, B, C, k separated by a single space. The integ
POJ C Looooops
a*x和b同餘N時,當b為gcd(a,N)的倍數時有整數解,設x0 = ex_gcd(a,N,b),可得符合條件的x的集合為:x0+k*n'(n' = N / gcd(a,N)); 題目很簡單,其實就是用尤拉定理求一下逆元即可,注意求出的逆元可能不是最小正整數。需要用公式求
POJ 2115 C Looooops 擴充套件gcd
很裸的擴充套件gcd 3月份做過一次 不過那時候稀裡糊塗不求甚解 最近又好好看了下擴充套件gcd 這就一sb題 ACcode: #include <iostream> #include &
c# 數組
blog com arr 整數 ray new 進行 一行 不能 1 什麽是數組? 數組是一種數據結構,包含同一種數據類型的多個元素。 2 數組的聲明? int [] Num; 註:聲明數組時,方括號 ([]) 必須跟在類型後面,而不是變量名後面。在 C# 中,將方括號放
C#中流寫入類StreamWriter的介紹
() virtual || 寫入 lock object 字符 html 更改 C#中流寫入類StreamWriter的介紹 (轉) 應用FileStream類需要許多額外的數據類型轉換工作,十分影響效率。使用StreamWriter類將提供更簡單,更方便的操作方式。
c#配置問題以及簡單防止sql註入,連接池問題,sqldatareader對象對於connection對象的釋放
c#添加引用。system configurationconfigurationManager.AppSettings[“”]<appSetings><add key=“” value=“”></appSetings><connectionStrings><
元數據管理器中存在錯誤。 實例化來自文件“\?C:Program FilesMicrosoft SQL ServerMSAS11.MSSQLSERVEROLAPDataTfs_Analysis.0.dbvDimTestCaseOverlay.874.dim.xml”的元數據對象時出錯。
參數配置 錯誤 manage 但是 加密 olap 右上角 alt 剛才 一、發現問題 啟動SQLSERVER的數據分析服務失敗 查看系統日誌錯誤如下: 雙擊錯誤後顯示詳細錯誤: 元數據管理器中存在錯誤。 實例化來自文件“\\?\C:\Pro
[c#]如何訪問 JArray 的元素
twitter () temp con bject array ace ebo pen JArray 格式文件。 public void TestJson() { var jsonString = @"{""trends"": [
c++將lambda作為callback函數
include lam 如果 pen init func per result out 想用c++發送http_post請求,用到了libcurl。 想將其包裝一下,因為默認http的響應結果是打印到stdout的,如果想將響應結果另外處理,需要自己定義一個callbac
C# 推送模板
doc -1 ges cnblogs images title src target 個推 C#推送模板、安卓個推、消息推送 http://docs.getui.com/server/csharp/template/ C# 推送模板
1.2 C語言---數組
c語言---數組1.2 C語言---數組 1.2.1 為什麽引入數組? 數組就是數組成的一個組,數就是一個特定數據類型的變量,組就是說好多數放在了一起。 1.2.2 怎麽定義數組? in
C#與MATLAB通信-2
fopen clas 時速 end available 文本 time div txt -1 與-2 都是通過桌面的文本文件.txt來實現C#與MATLAB端的數據傳輸,這個txt文件就起到了中間的連接,但若將服務器端放在雲服務器上,因為不在同一臺計算機中,所以不能找到一個