zoukankan      html  css  js  c++  java
  • codeforces C. Division 数学

    http://codeforces.com/contest/1445/problem/C

     1 #include<cstdio>
     2 #define rep(i,a,n) for(register ll i = a;i <= n;++i)
     3 #define per(i,n,a) for(register ll i = n;i >= a;--i)
     4 using namespace std;
     5 typedef long long ll;
     6 
     7 const ll Maxn = 100011;
     8 
     9 ll read(){
    10     ll a = 0;char c = getchar(),l = c;
    11     while(c < '0'||c > '9')l = c,c = getchar();
    12     while('0' <= c&&c <= '9')a = a*10+c-'0',c = getchar();
    13     if(l == '-')return -a;return a;
    14 }
    15 
    16 ll max(ll a,ll b){if(a > b)return a;return b;}
    17 
    18 ll prime[Maxn],v[Maxn],b[Maxn];
    19 ll cntp;
    20 
    21 void euler(){
    22     cntp = 0;
    23     rep(i,2,100010){
    24         if(!v[i])v[i] = i,prime[++cntp] = i;
    25         rep(j,1,cntp){
    26             if(prime[j] > v[i]||prime[j]*i > 100010)break;
    27             v[prime[j]*i] = prime[j];
    28         }
    29     }
    30     
    31 }
    32 
    33 int main(){
    34     euler();
    35     ll t = read();
    36     while(t--){
    37         ll x = read(),y = read(),ans = 1,z = y,cnt = 0;
    38         rep(i,1,cntp)if(z%prime[i] == 0){
    39             b[++cnt] = prime[i];//printf("working %d:
    ",b[cnt]);
    40             while(z%prime[i] == 0)z /= prime[i];
    41         }
    42         if(z > 1)b[++cnt] = z;
    43         rep(i,1,cnt){
    44             ll cntx = 0,cnty = 0,xx = x,yy = y;
    45             while(yy % b[i] == 0)yy /= b[i],cnty++;
    46             while(xx % b[i] == 0)xx /= b[i],cntx++;
    47             if(cntx < cnty){ans = x;break;}
    48             else{
    49                 rep(j,1,cnty-1)xx *= b[i];
    50 //                printf("---- %%%d %d
    ",b[i],xx);
    51                 ans = max(ans,xx);
    52             }
    53         }
    54         if(ans == 1){
    55             while(x % y == 0)x /= y;
    56             ans = x;
    57         }
    58         printf("%lld
    ",ans);
    59     }
    60 return 0;
    61 }
  • 相关阅读:
    监控里的主码流和子码流是什么意思
    监控硬盘容量计算
    一个能让你了解所有函数调用顺序的Android库
    电工选线
    oracle linux dtrace
    list all of the Oracle 12c hidden undocumented parameters
    Oracle Extended Tracing
    window 驱动开发
    win7 x64 dtrace
    How to Use Dtrace Tracing Ruby Executing
  • 原文地址:https://www.cnblogs.com/Wangsheng5/p/13916541.html
Copyright © 2011-2022 走看看