费马小定理(快速幂+逆元)
#include#define rep(i,a,b) for(int i=a;i<b;i++) #define T int t ;cin >> t;while(t--)using namespace std ; typedef long long ll;const ll mod = 1e9 + 7;long long quickpow(long long a,long long b) { if(b<0) return 0; long long ret=1; a%=mod; while(b) { if(b & 1 ) ret = ( ret *a ) % mod; b>>=1; a = (a * a)% mod; } return ret; }long long inv(long long a) { return quickpow(a,mod-2); } ll s[200000010];void solve() { ll inv2=inv(2); ll i; ll niyuan=inv2; ll sum=0,res=1; for(i=1;i<20000002;i++) { res=res*(1-niyuan+mod)%mod; niyuan=niyuan*inv2%mod; sum^=res; s[i]=sum; } }int main() { solve(); T { int n; scanf("%d",&n); printf("%lld\n",s[n]); } }
C Combination of Physics and Maths
#includetypedef long long ll;using namespace std;double a[205][205];double b[205];int main() { ll t; scanf("%lld",&t); while(t--) { memset(b, 0, sizeof b); ll n,m; ll i,j; double mm=0; scanf("%lld%lld",&n,&m); for(i=0; i<n; i++) { for(j=0; j<m; j++) { scanf("%lf",&a[i][j]); b[j]+=a[i][j]; mm=max(mm,b[j]/a[i][j]); } } printf("%.8lf\n",mm); } }
1
#include#include#includeusing namespace std;int main() { int n,k; scanf("%d%d",&n,&k); { if(k==0) { printf("-1"); } else { if((n*(n+1)/2)%n==k) { for(int i=1; i<=n; i++) { if(i!=1) { printf(" "); } printf("%d",i); } printf("\n"); } else { printf("-1\n"); } } } }