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 }
  • 相关阅读:
    html表单的创建
    mysql数据库连接标准操作
    关于Apache+MySQL+PHP下载及配置注意事项
    两个范例
    Stack类
    Collections类集
    key可以重复的map集合:IdentityHashMap
    foreach对集合的输出作用
    ListIterator接口
    【官方方法】xcode7免证书真机调试
  • 原文地址:https://www.cnblogs.com/Wangsheng5/p/13916541.html
Copyright © 2011-2022 走看看