青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Problem B : Always an Integer

Combinatorics is a branch of mathematics chiefly concerned with counting discrete objects. For instance, how many ways can you pick two people out of a crowd of n people? Into how many regions can you divide a circular disk by connecting n points on its boundary with one another? How many cubes are in a pyramid with square layers ranging from 1 × 1 to n × n cubes?


                   TFigure 1:T If we connect six points on the boundary of a circle, at most 31 regions are created.

Many questions like these have answers that can be reduced to simple polynomials in n. The answer to the first question above is n(n-1)/2, or (n^2-n)/2. The answer to the second is (n^4-6n^3+23n^2-18n+24)/24. The answer to the third is n(n+1)(2n+1)/6, or (2n^3+3n^2+n)/6. We write these polynomials in a standard form, as a polynomial with integer coefficients divided by a positive integer denominator. These polynomials are answers to questions that can have integer answers only. But since they have fractional coefficients, they look as if they could produce non-integer results! Of course, evaluating these particular polynomials on a positive integer always results in an integer. For other polynomials of similar form, this is not necessarily true. It can be hard to tell the two cases apart. So that, naturally, is your task.

Input
The input consists of multiple test cases, each on a separate line. Each test case is an expression in the form (P)/D, where P is a polynomial with integer coefficients and D is a positive integer denominator. P is a sum of terms of the form Cn^E, where the coefficient C and the exponent E satisfy the following conditions:
1. E is an integer satisfying 0 ≤ E ≤ 100. If E is 0, then Cn^E is expressed as C. If E is 1, then Cn^E is expressed as Cn, unless C is 1 or -1. In those instances, Cn^E is expressed as n or -n.
2. C is an integer. If C is 1 or -1 and E is not 0 or 1, then the Cn^E will appear as n^E or -n^E.
3. Only non-negative C values that are not part of the first term in the polynomial are preceded by +.
4. Exponents in consecutive terms are strictly decreasing.
5. C and D fit in a 32-bit signed integer.

 

See the sample input for details.
Input is terminated by a line containing a single period.

Output
For each test case, print the case number (starting with 1). Then print TAlways an integerT if the test casepolynomial evaluates to an integer for every positive integer n. Print TNot always an integerT otherwise. Print the output for separate test cases on separate lines. Your output should follow the same format as the sample output.

Sample Input
(n^2-n)/2
(2n^3+3n^2+n)/6
(-n^14-11n+1)/3
.

Output for the Sample Input
Case 1: Always an integer
Case 2: Always an integer
Case 3: Not always an integer

題目大概的意思是說:給定一個關于n的p次多項式,問該多項式是否為整值多項式。
根據定理:n次多項式f(n)是整值多項式當且僅當f(n)至少在n+1個連續的整數上都取整值。
只用將0-MAXPOW(取101)依次代入多項式的分子,并對分母d取模,判斷是否都為0即可。
至于為什么要取MAXPOW,而不是多項式f(n)的最大的次數max{pi}:為了使問題一般化,我們可以講所有的多項式都看成是MAXPOW次的,只不過當次數p>max{pi}時,其對應的系數ci全部為0,并不妨礙問題的解決。這樣一來,就不需要再額外求出f(n)的最大次數max{pi},使程序得到簡化。

399645  2009-04-23 07:44:07 Accepted 0.066 Minimum 19193  C++ 4119 - Always an integer
 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int MAXPOW = 101;
 5 int c[MAXPOW],d;
 6 char ch;
 7 
 8 int calculate(long long n){
 9     int i;
10     long long ans=0;
11     for(i=MAXPOW;i>=0;i--)
12         ans=(ans*n+c[i])%d;
13     return (int)ans;
14 }
15 bool judge(){
16     int i;
17     for(i=0;i<=MAXPOW;i++)
18         if(calculate(i)) return false;
19     return true;
20 }
21 int main(){
22     int end,ca=1,sign,value,pow;
23     while(true){
24         ch=getchar();
25         if(ch=='.'break;
26         memset(c,0,sizeof(c));
27         while(true){
28             end=0,scanf(")%n",&end);
29             if(end) break;
30             scanf("+");
31             sign=0,value=1,scanf("-%n",&sign);
32             scanf("%d",&value);
33             if(sign) value=-value;
34             scanf("%nn%n^%n",&pow,&pow,&pow);
35             if(pow>1) scanf("%d",&pow);
36             c[pow]+=value;
37         }
38         scanf("/%d",&d);
39         getchar();
40         printf("Case %d: ",ca++);
41         puts(judge() ? "Always an integer" : "Not always an integer");
42     }
43     return 0;
44 }

posted on 2009-04-23 12:51 極限定律 閱讀(1903) 評論(0)  編輯 收藏 引用 所屬分類: ACM-ICPC World Final 2008題解

<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

導航

統計

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美一区二区成人| 美女在线一区二区| 国产精品一卡二| 午夜国产精品视频免费体验区| 日韩一级黄色大片| 国产精品mv在线观看| 欧美一区二视频| 欧美在线观看网站| 亚洲国产aⅴ天堂久久| 亚洲欧洲精品一区| 欧美日韩国产色综合一二三四| 亚洲无限乱码一二三四麻| 亚洲欧美综合| 91久久久一线二线三线品牌| 亚洲精品中文字幕在线| 国产精品视频自拍| 欧美激情久久久| 欧美午夜宅男影院在线观看| 久久久久久久成人| 欧美精品在线观看播放| 欧美一级片在线播放| 麻豆国产va免费精品高清在线| 99视频精品免费观看| 午夜精品久久一牛影视| 亚洲韩国日本中文字幕| 亚洲一区二区三区中文字幕在线| 一区二区三区在线免费观看| 日韩视频免费在线| 黄色亚洲在线| 一区二区三区四区五区在线| 伊人成人在线| 亚洲一区国产精品| 亚洲三级影片| 久久九九免费视频| 午夜精品久久久久久久久| 免费成人你懂的| 欧美在线观看天堂一区二区三区| 女女同性精品视频| 久久久久久久性| 国产精品久久久久秋霞鲁丝| 欧美激情视频一区二区三区在线播放 | 国产私拍一区| 一二美女精品欧洲| 亚洲人成人一区二区在线观看| 午夜精品久久久久久久蜜桃app| 亚洲伦伦在线| 免费看的黄色欧美网站| 久久人人爽国产| 国产精品爽黄69| 亚洲线精品一区二区三区八戒| 亚洲精品在线观看免费| 久久噜噜亚洲综合| 久久亚洲一区二区三区四区| 国产精品极品美女粉嫩高清在线| 亚洲人成欧美中文字幕| 亚洲国产91| 久色成人在线| 欧美大片一区二区三区| 在线观看精品一区| 久久久久久9| 美女黄色成人网| 在线看不卡av| 免费成人av在线看| 亚洲国产精品久久久| 亚洲电影在线观看| 久久美女性网| 亚洲大片av| 99国产精品视频免费观看| 欧美极品在线视频| 9久re热视频在线精品| 中文国产亚洲喷潮| 国产精品久久久久久久久久尿| 亚洲深夜影院| 欧美在线综合视频| 在线播放中文字幕一区| 欧美成人a∨高清免费观看| 亚洲国产精品va在线看黑人| 亚洲精品综合精品自拍| 欧美色欧美亚洲高清在线视频| 亚洲一区二区三区四区五区午夜 | 亚洲精品精选| 欧美乱大交xxxxx| 在线视频精品一区| 久久国产成人| 最新国产拍偷乱拍精品| 欧美久久久久久久| 亚洲一区二区三区四区在线观看| 欧美一区二区三区在线| 激情自拍一区| 欧美日韩国产专区| 亚洲欧美日韩精品久久奇米色影视 | 中日韩视频在线观看| 国产精品狼人久久影院观看方式| 欧美在线视频观看| 欧美国产三区| 亚洲欧美色婷婷| 在线观看日韩av先锋影音电影院| 欧美理论电影网| 午夜在线一区| 亚洲激情在线观看| 久久久精品一区二区三区| 亚洲精品视频免费在线观看| 国产精品色午夜在线观看| 久久久免费精品| 中文在线资源观看视频网站免费不卡| 性欧美1819sex性高清| 亚洲激情在线观看| 国产伦一区二区三区色一情| 欧美wwwwww| 久久精品国产一区二区三区| 日韩一区二区精品| 欧美福利网址| 久久九九久精品国产免费直播| 一本色道久久综合亚洲精品高清 | 在线电影院国产精品| 欧美色精品天天在线观看视频| 久久国产88| 亚洲小视频在线| 最新日韩精品| 欧美不卡一卡二卡免费版| 欧美一区二区三区在线播放| 夜夜狂射影院欧美极品| 亚洲第一视频网站| 国产午夜精品一区理论片飘花| 欧美人成在线视频| 欧美阿v一级看视频| 久久精品国产77777蜜臀| 亚洲欧美国产毛片在线| 一本大道av伊人久久综合| 亚洲国内欧美| 亚洲国产精品ⅴa在线观看| 可以免费看不卡的av网站| 欧美一区国产二区| 性欧美18~19sex高清播放| 亚洲无线观看| 亚洲一区二区四区| 亚洲香蕉在线观看| 在线一区免费观看| 亚洲一区二区av电影| 中文久久乱码一区二区| 一区二区三欧美| 一区二区三区四区在线| 一本色道久久综合亚洲精品婷婷 | 国产欧美精品va在线观看| 国产精品捆绑调教| 国产精品久久国产三级国电话系列| 欧美日韩少妇| 国产精品国内视频| 国产精品中文字幕在线观看| 国产精品婷婷| 国产在线乱码一区二区三区| 一区二区在线看| 亚洲黑丝一区二区| 99re66热这里只有精品4| 一区二区三区精密机械公司| 亚洲午夜一区| 欧美在线视频一区| 久久夜色撩人精品| 亚洲国产精品福利| 99av国产精品欲麻豆| 亚洲在线不卡| 久久久久www| 欧美国产欧美亚洲国产日韩mv天天看完整 | 中文av一区特黄| 亚洲午夜一区二区三区| 欧美中文字幕在线观看| 猛男gaygay欧美视频| 欧美日韩美女在线| 国产日韩欧美自拍| 亚洲国产一区二区三区青草影视 | 一区二区视频免费完整版观看| 亚洲经典视频在线观看| 一区二区欧美激情| 久久久久国产精品人| 亚洲福利视频免费观看| 正在播放亚洲一区| 久久视频在线视频| 欧美午夜精品理论片a级大开眼界| 国产精品性做久久久久久| 亚洲第一在线| 午夜精品一区二区三区四区 | 蜜桃av噜噜一区| 99视频精品全部免费在线| 久久av一区二区| 欧美亚韩一区| 91久久在线播放| 久久精品国产精品亚洲综合| 欧美激情视频在线免费观看 欧美视频免费一 | 午夜一区二区三区在线观看| 欧美91视频| 国语自产精品视频在线看| 一区二区欧美在线观看| 免播放器亚洲| 亚洲欧美日韩国产综合在线| 欧美激情 亚洲a∨综合| 伊人久久婷婷色综合98网| 性久久久久久久久久久久| 99国产精品久久久久久久久久| 久久蜜桃精品| 国产一区二区日韩精品|