UVALive 4119 Always an integer (差分数列,模拟)
2014-11-17 13:17
330 查看
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraudAlways an integerTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluCombinatorics 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?
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <cstdio> using namespace std; string s; vector<pair<long long,long long> >vec; long long fast_mod(long long m,long long n,long long fenm) { long long ret=1; long long temp=m; while(n) { if(n&1) { ret=ret*temp; ret%=fenm; } temp=temp*temp; temp%=fenm; n>>=1; } return ret; } int main() { ios::sync_with_stdio(false); int cas=1; //freopen("in.in","r",stdin); while(cin>>s) { if(s==".")break; int len=s.length(); vec.clear(); int pos=0; while(pos<len&&s[pos]!='/')pos++; long long fenm=0; int index=pos+1; while(index<len) fenm=s[index++]-'0'+fenm*10; if(fenm==0)fenm=1; long long a,b; long long maxx=0; bool chac=0; for(int i=0;i<pos;) { chac=0; a=0,b=0; if(s[i]=='(')i++; if(s[i]==')'||s[i]=='/')break; if(s[i]=='+'||s[i]=='-') { if(s[i]=='-')chac=1; i++; } while(i<pos&&s[i]!='/'&&s[i]!='n'&&s[i]!=')') { a*=10; a+=s[i++]-'0'; } if(a==0)a=1; if(chac)a*=-1; if(s[i]=='/'||s[i]==')') { vec.push_back(make_pair(a,0)); break; } i++; if(s[i]=='^')i++; while(i<pos&&s[i]>='0'&&s[i]<='9') { b*=10; b+=s[i++]-'0'; } if(b==0)b=1; vec.push_back(make_pair(a,b)); maxx=max(b,maxx); } bool flag=0; long long temp; for(int i=1;i<=maxx+1;i++) { temp=0; for(int j=0;j<vec.size();j++) { temp+=(vec[j].first*fast_mod(i,vec[j].second,fenm))%fenm; temp%=fenm; } if(temp){flag=1;break;} } cout<<"Case "<<cas++<<": "; if(flag)cout<<"Not always an integer"<<endl; else cout<<"Always an integer"<<endl; s.clear(); } return 0; }View Code
相关文章推荐
- UVALive 4119 Always an integer(差分数列+模拟)
- LA 4119 (差分数列 多项式) Always an integer
- UVA - 1069 Always an integer (模拟)
- uva 1069 - Always an integer(数学+暴力)
- UVA 1069 - Always an integer(数论)
- LA 4119 - Always an integer
- LA 4119 Always an integer (数论+模拟)
- uva1069 Always an integer【解法一】
- UVA 1069 - Always an integer(数论)
- uva1069 Always an integer【解法二】
- uva1069 - Always an integer
- LA 4119 Always an integer (数学)
- UVaLive 6802 Turtle Graphics (水题,模拟)
- UVALive 5873 - Tree Inspections 【模拟】
- UVALive 6858 Frame (模拟)
- UVALive 7752 模拟
- UVALive 3971 Assemble(模拟 + 二分)
- uvalive 4254(二分+模拟)
- UVALive 6277 - Addictive Bubbles (模拟)
- UVALive 7503--模拟