uva1069 Always an integer【解法一】
来源:互联网 发布:如何避免社交网络 编辑:程序博客网 时间:2024/05/18 21:42
Combinatorics is a branch of mathematics chie y 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
an- other? How many cubes are in a pyramid with square layers ranging
from 1 1 to n n cubes? Many questions like these have answers that
can be reduced to simple polynomials in n . The answer to the rst
question above is n ( n
随机若干个n代入验证。
正解见【这里】。
#include<cstdio>#include<cstring>#include<cstdlib>#define LL long longconst int T=10000;LL a[110],t[110],d,r[10010];char s[100010];int n;bool init(){ int x,f,p=0; char c; scanf("%s",s); c=s[p++]; if (c=='.') return 0; n=0; c=s[p++]; while (c!=')') { n++; if (c=='-') { f=-1; c=s[p++]; } else f=1; if (c=='+') c=s[p++]; x=0; while (c>='0'&&c<='9') { x=x*10+c-'0'; c=s[p++]; } if (!x) x=1; x*=f; a[n]=x; if (c!='n') { t[n]=0; continue; } c=s[p++]; x=0; if (c=='^') { c=s[p++]; while (c>='0'&&c<='9') { x=x*10+c-'0'; c=s[p++]; } } else x=1; t[n]=x; } c=s[p++]; c=s[p++]; x=0; while (c>='0'&&c<='9') { x=x*10+c-'0'; c=s[p++]; } d=x; return 1;}LL pow(LL base,LL p){ LL ret=1; while (p) { if (p&1) ret=ret*base%d; base=base*base%d; p>>=1; } return ret;}bool solve(){ int i,j; LL x; for (i=1;i<=T;i++) { x=0; for (j=1;j<=n;j++) x=((x+pow(r[i],t[j])*a[j]%d)%d+d)%d; if (x) return 0; } return 1;}void make(){ int i; srand(123); for (i=1;i<=T;i++) r[i]=rand();}int main(){ int K=0; make(); while (init()) { printf("Case %d: ",++K); if (solve()) printf("Always an integer\n"); else printf("Not always an integer\n"); }}
0 0
- uva1069 Always an integer【解法一】
- uva1069 Always an integer【解法二】
- uva1069 - Always an integer
- Always an Integer LA4119
- worldfinals 2008 Always an integer
- uvaoj 1069 Always an integer
- uva 1069 - Always an integer(数学+暴力)
- UVA 1069 - Always an integer(数论)
- UVA - 1069 Always an integer (模拟)
- LA 4119 Always an integer (数学)
- UVALive 4119 Always an integer(差分数列+模拟)
- Integer to Roman 解法
- leetcode: Reverse Integer 菜鸟解法
- Reverse Integer问题及解法
- Integer Break问题及解法
- always @ (*)
- uva1069-数学归纳法
- switch quantity not an integer
- jQuery实现弹幕效果
- 面向接口编程详解(二)——编程实例
- 模板方法模式
- centos安装python3.5
- 监听EditText内容变化的两种方式
- uva1069 Always an integer【解法一】
- BroadcastReceiver学习(02)之有序广播
- 自定义类的加载器
- Collectd & InfluxDb & Grafana 之一: 常用系统统计
- nodejs curl 输出内容
- 使用微信公众号进行发红包
- AlarmManager 闹钟(全局定时器)
- 常用MD5工具类
- web -前端历程