worldfinals 2008 Always an integer
2013-04-22 16:10
525 查看
利用差分序列 p(n) 为K 次多项式 p(0)p(1) p(2) .........p(k) 均整除D 其一阶 差分序列 dp(0),dp(1)....dp(n) 均能整除D,类推可知 d^kp(0),d^kp(1).....可整除D,且差分序列最后 变为常数
#include<cstdio> #include<cstring> #include<queue> #include<vector> #include<iostream> #include<string> #include<sstream> #include<cctype> #include<set> #include<stack> #include<functional> #include<memory> #include<deque> #include<list> #include<cmath> #include<fstream> #include<cstdlib> #include<climits> #include<iomanip> #include<cstring> #include<memory> #include<bitset> #include<algorithm> using namespace std; typedef long long ll; typedef vector<int>VI; typedef vector<VI>VVI; typedef vector<VVI>VVVI; const int maxn = 711; const int mod = 1000000007; template<class T> T gcd(T a,T b){ return b?gcd(b,a%b):a;} template<class T> T lcm(T a,T b){ return a/gcd(a,b)*b;} char buf[maxn<<2]; ll POW(ll a,ll b,ll c) { ll res=1; while(b) { if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res; } ll E[maxn],p[maxn],D; int cnt=0; bool cal(int k,int n) { ll res=0,t; int i; for(i=0;i<cnt;++i) { t=E[i]%D; t=t*POW(k,p[i],D)%D; res=(res+t)%D; } return res==0; } bool ok(char ch) { return ch=='+'||ch=='-'; } int main() { ios::sync_with_stdio(false); int cas=0,i,j,beg; while(true) { cas++; cin>>buf; if(buf[0]=='.') break; char ch; cnt=0; memset(p,0,sizeof(p)); int sign,n,len=strlen(buf); if(buf[1]!='-') beg=0,buf[0]='+'; else beg=1; for(i=beg;i<len;) { if(buf[i]=='/') { D=0; for(j=i+1;j<len;++j) { D=D*10+(buf[j]-'0'); } break; } if(ok(buf[i])) { sign=1; if(buf[i]=='-') sign=-1; E[cnt]=0; for(j=i+1;buf[j]!='n'&&!ok(buf[j])&&buf[j]!=')';++j) { E[cnt]=E[cnt]*10+(buf[j]-'0'); } E[cnt]*=sign; if(!E[cnt]) E[cnt]=sign; i=j; p[cnt]=0; if(buf[i]=='n') { if(buf[i+1]=='^') { p[cnt]=0; for(j=i+2;!ok(buf[j])&&buf[j]!=')';++j) { p[cnt]=p[cnt]*10+(buf[j]-'0'); } } else j=i+1,p[cnt]=1; } i=j; if(buf[i]==')') ++i; cnt++; } } bool flag=true; for(n=0;n<=p[0];++n) { flag&=cal(n,cnt); if(!flag) break; } cout<<"Case "<<cas<<": "; if(flag) cout<<"Always an integer"<<endl; else cout<<"Not always an integer"<<endl; } return 0; }
相关文章推荐
- 2008 world final B (Always an Integer)
- uva1069 Always an integer【解法二】
- LA4119 -- Always an integer
- UVALive 4119 Always an integer(差分数列+模拟)
- uva1069 - Always an integer
- UVA 1069 - Always an integer(数论)
- LA 4119 (差分数列 多项式) Always an integer
- LA 4119 - Always an integer
- LA 4119 Always an integer (数学)
- UVA 1069 - Always an integer(数论)
- uvaoj 1069 Always an integer
- UVALive 4119 Always an integer (差分数列,模拟)
- UVA - 1069 Always an integer (模拟)
- uva 1069 - Always an integer(数学+暴力)
- uva1069 Always an integer【解法一】
- LA 4119 Always an integer (数论+模拟)
- Android打包Error:Error: Expected a color resource id (R.color.) but received an RGB integer [ResourceT
- 1.求整数最大的连续0的个数 BinaryGap Find longest sequence of zeros in binary representation of an integer.
- 消息: Sys.ArgumentOutOfRangeException: Value must be an integer
- error: aggregate value used where an integer was expected